fix: list_mutual sort by follow created_at, apply pagination in TestStore
This commit is contained in:
@@ -194,13 +194,14 @@ impl FollowRepository for PgFollowRepository {
|
|||||||
page: &PageParams,
|
page: &PageParams,
|
||||||
) -> Result<Paginated<User>, DomainError> {
|
) -> Result<Paginated<User>, DomainError> {
|
||||||
let total: i64 = sqlx::query_scalar(
|
let total: i64 = sqlx::query_scalar(
|
||||||
"SELECT COUNT(DISTINCT u.id)
|
"SELECT COUNT(*) FROM follows f1
|
||||||
FROM users u
|
WHERE f1.follower_id = $1 AND f1.state = 'accepted'
|
||||||
WHERE EXISTS (
|
AND EXISTS (
|
||||||
SELECT 1 FROM follows f1 WHERE f1.follower_id=$1 AND f1.following_id=u.id AND f1.state='accepted'
|
SELECT 1 FROM follows f2
|
||||||
) AND EXISTS (
|
WHERE f2.follower_id = f1.following_id
|
||||||
SELECT 1 FROM follows f2 WHERE f2.following_id=$1 AND f2.follower_id=u.id AND f2.state='accepted'
|
AND f2.following_id = f1.follower_id
|
||||||
)",
|
AND f2.state = 'accepted'
|
||||||
|
)",
|
||||||
)
|
)
|
||||||
.bind(user_id.as_uuid())
|
.bind(user_id.as_uuid())
|
||||||
.fetch_one(&self.pool)
|
.fetch_one(&self.pool)
|
||||||
@@ -208,14 +209,22 @@ impl FollowRepository for PgFollowRepository {
|
|||||||
.into_domain()?;
|
.into_domain()?;
|
||||||
|
|
||||||
let rows = sqlx::query_as::<_, crate::user::UserRow>(
|
let rows = sqlx::query_as::<_, crate::user::UserRow>(
|
||||||
"SELECT u.id,u.username,u.email,u.password_hash,u.display_name,u.bio,u.avatar_url,u.header_url,u.custom_css,u.local,u.ap_id,u.inbox_url,u.created_at,u.updated_at
|
"SELECT u.id, u.username, u.email, u.password_hash, u.display_name, u.bio,
|
||||||
|
u.avatar_url, u.header_url, u.custom_css, u.local,
|
||||||
|
u.created_at, u.updated_at
|
||||||
FROM users u
|
FROM users u
|
||||||
|
JOIN follows f1
|
||||||
|
ON f1.follower_id = $1
|
||||||
|
AND f1.following_id = u.id
|
||||||
|
AND f1.state = 'accepted'
|
||||||
WHERE EXISTS (
|
WHERE EXISTS (
|
||||||
SELECT 1 FROM follows f1 WHERE f1.follower_id=$1 AND f1.following_id=u.id AND f1.state='accepted'
|
SELECT 1 FROM follows f2
|
||||||
) AND EXISTS (
|
WHERE f2.follower_id = u.id
|
||||||
SELECT 1 FROM follows f2 WHERE f2.following_id=$1 AND f2.follower_id=u.id AND f2.state='accepted'
|
AND f2.following_id = $1
|
||||||
|
AND f2.state = 'accepted'
|
||||||
)
|
)
|
||||||
ORDER BY u.created_at DESC LIMIT $2 OFFSET $3"
|
ORDER BY f1.created_at DESC
|
||||||
|
LIMIT $2 OFFSET $3",
|
||||||
)
|
)
|
||||||
.bind(user_id.as_uuid())
|
.bind(user_id.as_uuid())
|
||||||
.bind(page.limit())
|
.bind(page.limit())
|
||||||
|
|||||||
@@ -475,12 +475,18 @@ impl FollowRepository for TestStore {
|
|||||||
following_ids.intersection(&follower_ids).cloned().collect();
|
following_ids.intersection(&follower_ids).cloned().collect();
|
||||||
drop(follows);
|
drop(follows);
|
||||||
let users = self.users.lock().unwrap();
|
let users = self.users.lock().unwrap();
|
||||||
let items: Vec<User> = users
|
let all_items: Vec<User> = users
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|u| mutual_ids.contains(&u.id))
|
.filter(|u| mutual_ids.contains(&u.id))
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
let total = items.len() as i64;
|
let total = all_items.len() as i64;
|
||||||
|
let offset = page.offset() as usize;
|
||||||
|
let items: Vec<User> = all_items
|
||||||
|
.into_iter()
|
||||||
|
.skip(offset)
|
||||||
|
.take(page.limit() as usize)
|
||||||
|
.collect();
|
||||||
Ok(Paginated {
|
Ok(Paginated {
|
||||||
items,
|
items,
|
||||||
total,
|
total,
|
||||||
|
|||||||
Reference in New Issue
Block a user