Skip to content

Implemente federated instances view (fixes #6063)#6089

Merged
dessalines merged 6 commits intomainfrom
federated-instances-view
Oct 23, 2025
Merged

Implemente federated instances view (fixes #6063)#6089
dessalines merged 6 commits intomainfrom
federated-instances-view

Conversation

@Nutomic
Copy link
Copy Markdown
Member

@Nutomic Nutomic commented Oct 17, 2025

  • New FederatedInstanceView which includes all available data
  • Has parameter type: "Linked" | "Allowed" | "Blocked"
  • domain filter
  • Including pagination, because eg lemmy.ml has 10k linked instances

@Nutomic Nutomic force-pushed the federated-instances-view branch from b96e09c to 0845654 Compare October 17, 2025 12:24

// Show recently updated instances and those with valid metadata first
// TODO: doesnt support keys_last() or different order per key.
// should be `key::updated_at.desc(), instance::software.asc().nulls_last()`
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dullbananas Would be nice if the pagination library could support this.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the null order and mixing asc/desc can't be done in cursor pagination (without possible loss of efficient index scans) until it's supported by Postgresql's comparison operators.

For this query, use reversetimestampkey (from lemmy_db_schema) for updated_at, and remove nulls_last for software because nulls are greater than non-null by default (meaning nulls_last is the default for ascending order).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont find reversetimestampkey, where exactly is it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc we removed that.

TBH I think SortDirection::Desc, even for software (or null software) like you have below is fine. updated_at is already going to be unique enough.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I simply removed the comment.

})
}

impl FederatedInstanceView {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are the main changes.

@Nutomic Nutomic force-pushed the federated-instances-view branch from 8bf569b to 026e38f Compare October 17, 2025 14:04
}

impl FederatedInstanceView {
pub async fn list(pool: &mut DbPool<'_>, data: GetFederatedInstances) -> LemmyResult<Vec<Self>> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super big on passing the query struct directly into the list, especially since a lot of the objects get transformed, or need to make other DB calls and checks before doing list, which should be a single list query.

Everywhere else we use either a Query object with a list method on it, or pass in all the params individually. You should probably create aFederationQuery object, especially since you need to pre-fetch cursor data. Check out crates/api/api/src/federation/search.rs for an example.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know its done like that in other places, and there it usually makes sense. But here is no need for any transformations, and its only called from a single place so theres no real need for an extra query struct.


// Show recently updated instances and those with valid metadata first
// TODO: doesnt support keys_last() or different order per key.
// should be `key::updated_at.desc(), instance::software.asc().nulls_last()`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc we removed that.

TBH I think SortDirection::Desc, even for software (or null software) like you have below is fine. updated_at is already going to be unique enough.

@dessalines dessalines merged commit dc6ee1c into main Oct 23, 2025
2 checks passed
@dessalines dessalines deleted the federated-instances-view branch October 23, 2025 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants