From 508b6239e3a07d25fe212a41ab79b27874728fdb Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Mon, 19 Jan 2026 17:47:57 +0000 Subject: [PATCH] appview: remove `db.GetReaction()` After refactoring record deletion logic, we only need `db.GetReactionStatus` Signed-off-by: Seongmin Lee --- appview/db/reaction.go | 56 +++++++++++++++++++------------------------------------- appview/issues/issues.go | 5 ++++- appview/pulls/pulls.go | 7 +++++-- 3 file(s) changed, 28 insertion(s)(+), 40 deletion(s)(-) diff --git a/appview/db/reaction.go b/appview/db/reaction.go --- a/appview/db/reaction.go +++ b/appview/db/reaction.go @@ -2,7 +2,6 @@ import ( "fmt" - "log" "time" "github.com/bluesky-social/indigo/atproto/syntax" @@ -24,32 +23,6 @@ reaction.Created.Format(time.RFC3339), ) return err -} - -// Get a reaction record -func GetReaction(e Execer, did string, subjectAt syntax.ATURI, kind models.ReactionKind) (*models.Reaction, error) { - query := ` - select did, subject_at, created, rkey - from reactions - where did = ? and subject_at = ? and kind = ?` - row := e.QueryRow(query, did, subjectAt, kind) - - var reaction models.Reaction - var created string - err := row.Scan(&reaction.ReactedByDid, &reaction.ThreadAt, &created, &reaction.Rkey) - if err != nil { - return nil, err - } - - createdAtTime, err := time.Parse(time.RFC3339, created) - if err != nil { - log.Println("unable to determine followed at time") - reaction.Created = time.Now() - } else { - reaction.Created = createdAtTime - } - - return &reaction, nil } // Remove a reaction @@ -133,19 +106,28 @@ return reactionMap, rows.Err() } -func GetReactionStatus(e Execer, userDid string, threadAt syntax.ATURI, kind models.ReactionKind) bool { - if _, err := GetReaction(e, userDid, threadAt, kind); err != nil { - return false - } else { - return true - } +func GetReactionStatus(e Execer, userDid string, threadAt syntax.ATURI, kind models.ReactionKind) (bool, error) { + var exists bool + err := e.QueryRow( + `select exists ( + select 1 from reactions + where did = ? and subject_at = ? and kind = ? + )`, + userDid, + threadAt, + kind, + ).Scan(&exists) + return exists, err } -func GetReactionStatusMap(e Execer, userDid string, threadAt syntax.ATURI) map[models.ReactionKind]bool { +func GetReactionStatusMap(e Execer, userDid string, threadAt syntax.ATURI) (map[models.ReactionKind]bool, error) { statusMap := map[models.ReactionKind]bool{} for _, kind := range models.OrderedReactionKinds { - count := GetReactionStatus(e, userDid, threadAt, kind) - statusMap[kind] = count + reacted, err := GetReactionStatus(e, userDid, threadAt, kind) + if err != nil { + return nil, err + } + statusMap[kind] = reacted } - return statusMap + return statusMap, nil } diff --git a/appview/issues/issues.go b/appview/issues/issues.go --- a/appview/issues/issues.go +++ b/appview/issues/issues.go @@ -99,7 +99,10 @@ userReactions := map[models.ReactionKind]bool{} if user != nil { - userReactions = db.GetReactionStatusMap(rp.db, user.Active.Did, issue.AtUri()) + userReactions, err = db.GetReactionStatusMap(rp.db, user.Active.Did, issue.AtUri()) + if err != nil { + l.Error("failed to get issue reaction status", "err", err) + } } backlinks, err := db.GetBacklinks(rp.db, issue.AtUri()) diff --git a/appview/pulls/pulls.go b/appview/pulls/pulls.go --- a/appview/pulls/pulls.go +++ b/appview/pulls/pulls.go @@ -227,12 +227,15 @@ reactionMap, err := db.GetReactionMap(s.db, 20, pull.AtUri()) if err != nil { - log.Println("failed to get pull reactions") + s.logger.Error("failed to get pull reaction status", "err", err) } userReactions := map[models.ReactionKind]bool{} if user != nil { - userReactions = db.GetReactionStatusMap(s.db, user.Active.Did, pull.AtUri()) + userReactions, err = db.GetReactionStatusMap(s.db, user.Active.Did, pull.AtUri()) + if err != nil { + s.logger.Error("failed to get pull reaction status", "err", err) + } } labelDefs, err := db.GetLabelDefinitions( -- tangled.sh