feat(post): count how many times a post has been quoted - #240
Closed
aquie00t wants to merge 1 commit into
Closed
Conversation
Posts carry a quoteCount alongside likeCount and commentCount, so a client can draw the quote badge without counting rows. Denormalised for the same reason the other two are: the read path is far hotter than the write path, and counting the quotes relation would put a subquery on every feed item. Keeping that counter honest makes post creation a multi-step write, so CreatePostUseCase moves onto TransactionPort: the post, the quoted post's existence check and the increment now commit or roll back together. A post that existed without having been counted would leave the badge permanently short with nothing to notice it afterwards. The bot check stays outside the transaction because it only reads, and so do the cache purge and the follower fan-out, which must not hold the write open or roll it back. Deleting a quote gives the count back in the same transaction as the delete. Deleting a quoted post needs no such care: its quotes are cascaded away with it and no surviving row was counting them. Known drift, matching likeCount today: hard-deleting a user cascades their posts away without decrementing the posts those quoted. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015JC6UgjwRSJ3KHToPYqBPC
This was referenced Aug 30, 2026
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Alıntı özelliğinin ikinci PR'ı. Base'i
maindeğil, #239'un dalı (feature/post-quotes) — hepsi tek seferde merge edilip tek deploy olacak.Ne değişti
quoteCountkolonu —likeCount/commentCountile aynı blokta, aynı adlandırmayla (bu modeldeki kardeş sayaçlar@map'siz). Migration'da savunma amaçlı geri doldurma da var: iki migration arasına bir deploy girerse sayaç sessizce sıfırda kalmasın.CreatePostUseCase→TransactionPort— post, alıntılanan postun varlık kontrolü ve sayaç artırımı artık birlikte commit/rollback oluyor. Sayılmadan var olan bir post, rozeti kalıcı olarak eksik bırakır ve sonradan fark etmenin ucuz bir yolu yok.DeletePostUseCase— alıntı silinince sayaç, silme ile aynı transaction'da geri veriliyor.PostItemSchema'yaquoteCount; alıntı kartı sayaç taşımıyor (PR 1'in yalın kart kararı).Kararlar
_count: Prisma_count: { quotes: true }her feed satırına alt sorgu ekler ve modeldeki iki kardeş sayaçla tutarsız düşerdi. Okuma yolu yazma yolundan çok daha sıcak.likeCount'ta bugün aynısı var; tek başına yeni bir mutabakat mekanizması icat etmek yerine mevcut davranış korundu. Purge job'ında mutabakat ayrı bir iş.CreatePostUseCase'tenpostRepositorybağımlılığı çıkarıldı — yazma yolu tamamenctx.postRepository'ye taşındığı için ölü kalıyordu.Doğrulama
pnpm test:unit→ 886/886 geçti. Yeni testler: create-post transaction mock'larına geçti (+3 durum), delete-post decrement (+3), mapperquoteCount(+3).pnpm lint,pnpm format:check,tsc --noEmittemiz.migrate diffsıfır drift.TransactionServiceile smoke: yeni post 0'dan başlıyor, alıntı sayıyor, ikinci alıntı tekrar sayıyor, alıntı silinince sayaç geri geliyor, olmayan bir postu alıntılama reddediliyor ve transaction geriye sarıp arkasında hiçbir şey bırakmıyor, orijinal silinince kalan alıntı cascade ile gidiyor.migrate resetçalışmadığı için CI'da koşacaklar.Sonraki PR'lar
NotificationType.QUOTE+ realtime bildirimGET /posts/:id/quotes+ metinsiz alıntı (saf repost)🤖 Generated with Claude Code
https://claude.ai/code/session_015JC6UgjwRSJ3KHToPYqBPC