Skip to content

feat(post): count how many times a post has been quoted - #240

Closed
aquie00t wants to merge 1 commit into
feature/post-quotesfrom
feature/post-quote-count
Closed

feat(post): count how many times a post has been quoted#240
aquie00t wants to merge 1 commit into
feature/post-quotesfrom
feature/post-quote-count

Conversation

@aquie00t

Copy link
Copy Markdown
Collaborator

Alıntı özelliğinin ikinci PR'ı. Base'i main değil, #239'un dalı (feature/post-quotes) — hepsi tek seferde merge edilip tek deploy olacak.

Ne değişti

  • quoteCount kolonulikeCount / commentCount ile 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.
  • CreatePostUseCaseTransactionPort — 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.
  • YanıtPostItemSchema'ya quoteCount; alıntı kartı sayaç taşımıyor (PR 1'in yalın kart kararı).

Kararlar

  • Denormalize kolon vs _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.
  • Transaction'ın dışında kalanlar: bot/tip kontrolü (salt okunur), cache temizleme ve takipçi fan-out'u — yazmayı açık tutmamalı ya da geri sardırmamalı.
  • Orijinal silinince decrement yok: alıntıları cascade ile gidiyor ve hayatta kalan hiçbir satır onları saymıyordu; sayaç kendiliğinden tutarlı.
  • Bilinen kayma: kullanıcı hard-delete edilince postları cascade ile silinir, bunların alıntıladığı postların sayacı yüksek kalır. 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'ten postRepository bağımlılığı çıkarıldı — yazma yolu tamamen ctx.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), mapper quoteCount (+3).
  • pnpm lint, pnpm format:check, tsc --noEmit temiz.
  • Migration test DB'sine uygulandı; migrate diff sıfır drift.
  • Gerçek TransactionService ile 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.
  • Integration (+2) ve E2E (+2) testleri eklendi; lokalde migrate reset çalışmadığı için CI'da koşacaklar.

Sonraki PR'lar

  • PR 3NotificationType.QUOTE + realtime bildirim
  • PR 4GET /posts/:id/quotes + metinsiz alıntı (saf repost)

🤖 Generated with Claude Code

https://claude.ai/code/session_015JC6UgjwRSJ3KHToPYqBPC

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
@aquie00t

Copy link
Copy Markdown
Collaborator Author

Kodu #242'nin squash merge'ü ile main'e girdi (faa97c7) — zincirin tamamı tek commit olarak birleşti. Bu PR, base dalı silinince otomatik kapandı; tartışma burada okunabilir kalıyor.

@aquie00t
aquie00t deleted the feature/post-quote-count branch August 30, 2026 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant