fix(mod-chat): show direct post URLs and live reaction counts#208
fix(mod-chat): show direct post URLs and live reaction counts#208ohld merged 1 commit intoproductionfrom
Conversation
The mod-chat reply was wrong on two axes: 1. JOIN bug: `mrt.post_id = m.raw_meme_id` never matched because `meme.raw_meme_id` references `meme_raw_telegram.id` (PK), not `post_id` (TG message id). The query silently fell back to the channel-only `meme_source.url` (e.g. `https://t.me/matroskina_meme`). 2. Stale counts: views/likes/dislikes came from `meme_stats`, which is refreshed by a 15-min cron. Memes served right before the moderator forwarded them showed 0/0/0. Fix: - JOIN on `mrt.id = m.raw_meme_id` (also gated by `msrc.type='telegram'`). - Add `meme_raw_vk` join so VK memes get their direct post URL. - Build the TG post link from `msrc.url || '/' || mrt.post_id` (the stored `mrt.url` has a `/s/` preview prefix — not what we want for a "click to see the original post" link). - Aggregate views/likes/dislikes live from `user_meme_reaction` so the reply reflects reality immediately, not whatever the cron last saw.
|
STAFF ENGINEER REVIEW: APPROVED Diff verified against schema:
Two P2 notes (non-blocking — admin-only handler, fires a few times per day):
Neither blocks landing. Squash-merging via |
|
✅ Approved + squash-merged. CI was already green when --auto ran. |
Why
Moderator forwarded meme #10133049 to the mod chat. The bot replied:
Both halves were wrong:
Source link was channel-only, not the post. The current query did
LEFT JOIN meme_raw_telegram ON mrt.post_id = m.raw_meme_id, butmeme.raw_meme_idis thememe_raw_telegram.id(autoincrement PK),not the Telegram
post_id. The join silently failed, so we fellback to
meme_source.url(the channel root).Counts read from
meme_stats, which is on a 15-min cron. Memesserved right before the forward have no row yet →
COALESCE(..., 0)reports 0 views / 0 likes / 0 dislikes even though the user clearly
received the meme.
What changed
src/tgbot/handlers/chat/mod_chat_stat.py:mrt.id = m.raw_meme_id(gated bymsrc.type='telegram').meme_raw_vkjoin so VK memes get their direct post URL too.msrc.url || '/' || mrt.post_id. The storedmrt.urlhas the/s/preview prefix (https://t.me/s/channel/12345),which is the embedded-channel-view variant — not what you want when
clicking through to "this exact post".
user_meme_reactionso thereply reflects reality immediately, no cron lag.
sec_to_reactstill comes frommeme_stats(median over a window —not worth recomputing inline).
Test plan
confirm the reply shows non-zero views and a
https://t.me/<channel>/<post_id>link that opens the exact post.
meme_statswould have reported (within rounding).src:is the?w=wall...post link, not the community root.