sublinks / sublinks-api

MIT License
68 stars 17 forks source link

Post score not correctly updated on flood of vote requests #311

Closed kgilles closed 2 months ago

kgilles commented 2 months ago

For the seeder script in our Docker setup I have it create some entities automatically. One thing I've recently looked into is making some API requests in parallel. When doing this for the like/vote requests on a post, I noticed that the post score doesn't end up matching reality.

For example, I create 20 different +1 votes(from different users) on a single post. I do this by sending 20 API requests towards POST /api/v3/post/like at the same time.

I can then retrieve all 20 vote entities using the GET /api/v3/post/like/list route. But when I retrieve the post itself, either via GET /api/v3/post or GET /api/v3/post/list, its score will be less than 20. Usually in the range of 7-10.

I only see this issue when sending multiple requests all at once. It works fine if I make each vote request sequentially.

Pdzly commented 2 months ago

This is a issue with the delay created by:

  1. The post/list endpoint returns aggregated data, and this is aggregated through events
  2. The ORM isnt saving it immediatly to the db, it only "merges" it to the cache ( BUT this should be reflecting directly to the aggregated data )

Image