Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize .mark_as_read! and extend to work on relations #1

Merged
merged 1 commit into from
May 12, 2023

Conversation

HwakyoungLee
Copy link

@HwakyoungLee HwakyoungLee commented May 12, 2023

by fatkodima

This PR optimizes .mark_as_read! to be roughly one query for collections and for relations.

Implements

Partly done by ledermann#93 - an optimized "one query" solution for scopes is still pending.

from ledermann#73 and fixes ledermann#80.

This is a an improvement over my previous PR ledermann#94, so probably that can be closed.

Implementation is based on INSERT ... ON CONFLICT DO ... like feature on modern databases (aka UPSERT) using gem upsert which uses native support of "upsert" or emulates if db does not provide it and allows to insert many records at once without db constraint violation.

PostgresSQL requires to have a unique constraint (just index is not sufficient) as so upsert gem, as stated on gem's readme so migration to add such was created.

@HwakyoungLee HwakyoungLee merged commit a75caf8 into grepp:master May 12, 2023
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.

Slow N+1 query
2 participants