From e5c27a9fea15cf56d7c0e47a076065ab01cfebe6 Mon Sep 17 00:00:00 2001 From: kim Date: Thu, 12 Sep 2024 11:58:13 +0100 Subject: [PATCH] ensure returned ID lists are ordered correctly --- internal/db/bundb/list.go | 4 ++++ internal/db/bundb/tag.go | 6 ------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/internal/db/bundb/list.go b/internal/db/bundb/list.go index 2a7c58772..29f32a1b6 100644 --- a/internal/db/bundb/list.go +++ b/internal/db/bundb/list.go @@ -248,6 +248,7 @@ func (l *listDB) getListIDsByAccountID(ctx context.Context, accountID string) ([ Table("lists"). Column("id"). Where("? = ?", bun.Ident("account_id"), accountID). + OrderExpr("? DESC", bun.Ident("created_at")). Exec(ctx, &listIDs); err != nil && !errors.Is(err, db.ErrNoEntries) { return nil, err @@ -267,6 +268,7 @@ func (l *listDB) getListIDsWithFollowID(ctx context.Context, followID string) ([ Table("list_entries"). Column("list_id"). Where("? = ?", bun.Ident("follow_id"), followID). + OrderExpr("? DESC", bun.Ident("created_at")). Exec(ctx, &listIDs); err != nil && !errors.Is(err, db.ErrNoEntries) { return nil, err @@ -286,6 +288,7 @@ func (l *listDB) GetFollowIDsInList(ctx context.Context, listID string, page *pa Table("list_entries"). Column("follow_id"). Where("? = ?", bun.Ident("list_id"), listID). + OrderExpr("? DESC", bun.Ident("created_at")). Exec(ctx, &followIDs) if err != nil && !errors.Is(err, db.ErrNoEntries) { return nil, err @@ -307,6 +310,7 @@ func (l *listDB) GetAccountIDsInList(ctx context.Context, listID string, page *p Join("INNER JOIN ?", bun.Ident("list_entries")). JoinOn("? = ?", bun.Ident("follows.id"), bun.Ident("list_entries.follow_id")). Where("? = ?", bun.Ident("list_entries.list_id"), listID). + OrderExpr("? DESC", bun.Ident("list_entries.created_at")). Exec(ctx, &accountIDs) if err != nil && !errors.Is(err, db.ErrNoEntries) { return nil, err diff --git a/internal/db/bundb/tag.go b/internal/db/bundb/tag.go index 67af0cb4e..75daf3c33 100644 --- a/internal/db/bundb/tag.go +++ b/internal/db/bundb/tag.go @@ -197,12 +197,6 @@ func (t *tagDB) IsAccountFollowingTag(ctx context.Context, accountID string, tag if err != nil { return false, err } - - // NOTE: it should only become useful to cache - // FollowedTag{} objects separately here (for - // caching by AccountID.TagID) only if the number - // of accounts following a tag becomes rather ridiculous, - // i.e. in the order of thousands. So we should be good. return slices.Contains(followingTagIDs, tagID), nil }