Skip to content

Commit 030be00

Browse files
Napuuclaude
andcommitted
Fix reaction counts not updating due to emoji parameter binding issue
Move emoji-to-column mapping from DuckDB CASE WHEN expressions to Go, avoiding potential parameter binding mismatch with emoji string literals. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2088f8d commit 030be00

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

pkg/utils/stats_db.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,22 @@ func RecordVideoPost(db *sql.DB, entry VideoStatEntry) error {
7676
// message. emoji should be the raw emoji character (e.g. "👍"). Unrecognised
7777
// emoji are ignored. A delta that matches no row is silently ignored.
7878
func UpdateReactionCount(db *sql.DB, platform, groupId, botMessageId, emoji string, delta int) error {
79-
query := `
79+
var column string
80+
switch emoji {
81+
case EmojiThumbsUp:
82+
column = "thumbs_up_count"
83+
case EmojiThumbsDown:
84+
column = "thumbs_down_count"
85+
default:
86+
return nil // unrecognised emoji, nothing to update
87+
}
88+
89+
query := fmt.Sprintf(`
8090
UPDATE video_stats
81-
SET thumbs_up_count = thumbs_up_count + CASE WHEN ? = '👍' THEN ? ELSE 0 END,
82-
thumbs_down_count = thumbs_down_count + CASE WHEN ? = '👎' THEN ? ELSE 0 END
91+
SET %s = %s + ?
8392
WHERE platform = ? AND group_id = ? AND bot_message_id = ?
84-
`
85-
_, err := db.Exec(query,
86-
emoji, delta,
87-
emoji, delta,
88-
platform, groupId, botMessageId,
89-
)
93+
`, column, column)
94+
_, err := db.Exec(query, delta, platform, groupId, botMessageId)
9095
if err != nil {
9196
return fmt.Errorf("failed to update reaction count: %w", err)
9297
}

0 commit comments

Comments
 (0)