Skip to content

Conversation

@benkonrath
Copy link
Contributor

This update uses an update query with an F expression to atomically increment nr_times_visited. The update query is run using to transaction.on_commit to ensure that the value is only incremented when the current transaction succeeds (transaction.on_commit calls the function immediately if there is no transaction).

I also set DEFAULT_AUTO_FIELD to BigAutoField to silence the warning when running the tests.

Feedback is appreciated. Feel free to also edit the PR if there are changes you want to make.

@alextreme
Copy link
Member

Thanks Ben, appreciate the effort! This is of course a better implementation than what I did years back

@alextreme alextreme self-requested a review February 11, 2025 18:46
@alextreme alextreme merged commit 34d4f09 into maykinmedia:master Feb 11, 2025
12 checks passed
@benkonrath
Copy link
Contributor Author

I think some of this stuff didn't exist in Django back then. :-) Thanks for maintaining this app all these years!

@benkonrath benkonrath deleted the atomic-increment branch April 22, 2025 07:45
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.

2 participants