openHPI / codeocean

CodeOcean is an automated assessment tool for web-based coding exercises
BSD 3-Clause "New" or "Revised" License
64 stars 27 forks source link

RfCs: Correctly increment `times_featured` counter #2588

Closed MrSerth closed 3 days ago

MrSerth commented 3 days ago

Previously, the counter was only changed in memory but not persisted. Rather than adding a .save call, I decided to use the bang method (despite skipping model validations). This, however, will improve the SQL query and prevent any concurrent updates that otherwise wouldn't be atomic.

The resulting SQL query is really nice:

UPDATE "request_for_comments" SET "times_featured" = COALESCE("times_featured", 0) + 1 WHERE "request_for_comments"."id" = $1
codecov[bot] commented 3 days ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 69.52%. Comparing base (d99a715) to head (9d5867b). Report is 26 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #2588 +/- ## ======================================= Coverage 69.52% 69.52% ======================================= Files 202 202 Lines 6360 6360 ======================================= Hits 4422 4422 Misses 1938 1938 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.