fix: list_mutual sort by follow created_at, apply pagination in TestStore
This commit is contained in:
@@ -194,12 +194,13 @@ impl FollowRepository for PgFollowRepository {
|
||||
page: &PageParams,
|
||||
) -> Result<Paginated<User>, DomainError> {
|
||||
let total: i64 = sqlx::query_scalar(
|
||||
"SELECT COUNT(DISTINCT u.id)
|
||||
FROM users u
|
||||
WHERE EXISTS (
|
||||
SELECT 1 FROM follows f1 WHERE f1.follower_id=$1 AND f1.following_id=u.id AND f1.state='accepted'
|
||||
) AND EXISTS (
|
||||
SELECT 1 FROM follows f2 WHERE f2.following_id=$1 AND f2.follower_id=u.id AND f2.state='accepted'
|
||||
"SELECT COUNT(*) FROM follows f1
|
||||
WHERE f1.follower_id = $1 AND f1.state = 'accepted'
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM follows f2
|
||||
WHERE f2.follower_id = f1.following_id
|
||||
AND f2.following_id = f1.follower_id
|
||||
AND f2.state = 'accepted'
|
||||
)",
|
||||
)
|
||||
.bind(user_id.as_uuid())
|
||||
@@ -208,14 +209,22 @@ impl FollowRepository for PgFollowRepository {
|
||||
.into_domain()?;
|
||||
|
||||
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
|
||||
JOIN follows f1
|
||||
ON f1.follower_id = $1
|
||||
AND f1.following_id = u.id
|
||||
AND f1.state = 'accepted'
|
||||
WHERE EXISTS (
|
||||
SELECT 1 FROM follows f1 WHERE f1.follower_id=$1 AND f1.following_id=u.id AND f1.state='accepted'
|
||||
) AND EXISTS (
|
||||
SELECT 1 FROM follows f2 WHERE f2.following_id=$1 AND f2.follower_id=u.id AND f2.state='accepted'
|
||||
SELECT 1 FROM follows f2
|
||||
WHERE f2.follower_id = u.id
|
||||
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(page.limit())
|
||||
|
||||
@@ -475,12 +475,18 @@ impl FollowRepository for TestStore {
|
||||
following_ids.intersection(&follower_ids).cloned().collect();
|
||||
drop(follows);
|
||||
let users = self.users.lock().unwrap();
|
||||
let items: Vec<User> = users
|
||||
let all_items: Vec<User> = users
|
||||
.iter()
|
||||
.filter(|u| mutual_ids.contains(&u.id))
|
||||
.cloned()
|
||||
.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 {
|
||||
items,
|
||||
total,
|
||||
|
||||
Reference in New Issue
Block a user