From 0aeb78eb3c0584a050b720b0077733a4c1919a1e Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Tue, 20 Jan 2026 02:47:57 +0900 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/single.go | 5 +++- 3 files changed, 27 insertions(+), 39 deletions(-) diff --git a/appview/db/reaction.go b/appview/db/reaction.go index a71da75f..8b1b18b8 100644 --- a/appview/db/reaction.go +++ b/appview/db/reaction.go @@ -2,7 +2,6 @@ package db import ( "fmt" - "log" "time" "github.com/bluesky-social/indigo/atproto/syntax" @@ -26,32 +25,6 @@ func UpsertReaction(e Execer, reaction models.Reaction) error { 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 func DeleteReaction(e Execer, did syntax.DID, subjectAt syntax.ATURI, kind models.ReactionKind) ([]syntax.ATURI, error) { var deleted []syntax.ATURI @@ -142,19 +115,28 @@ func GetReactionMap(e Execer, userLimit int, subjectAt syntax.ATURI) (map[models 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 index c1233fb1..2e422f8e 100644 --- a/appview/issues/issues.go +++ b/appview/issues/issues.go @@ -103,7 +103,10 @@ func (rp *Issues) RepoSingleIssue(w http.ResponseWriter, r *http.Request) { userReactions := map[models.ReactionKind]bool{} if user != nil { - userReactions = db.GetReactionStatusMap(rp.db, user.Did, issue.AtUri()) + userReactions, err = db.GetReactionStatusMap(rp.db, user.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/single.go b/appview/pulls/single.go index e75e2143..442bde8e 100644 --- a/appview/pulls/single.go +++ b/appview/pulls/single.go @@ -167,7 +167,10 @@ func (s *Pulls) repoPullHelper(w http.ResponseWriter, r *http.Request, interdiff userReactions := map[models.ReactionKind]bool{} if user != nil { - userReactions = db.GetReactionStatusMap(s.db, user.Did, pull.AtUri()) + userReactions, err = db.GetReactionStatusMap(s.db, user.Did, pull.AtUri()) + if err != nil { + l.Error("failed to get pull reaction status", "err", err) + } } labelDefs, err := db.GetLabelDefinitions( -- 2.51.2