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

Avoid WHERE IN for comment migration query #28500

Closed
wants to merge 1 commit into from

Conversation

earl-warren
Copy link
Contributor

  • Rewrite UpdateCommentsMigrationsByType to not use WHERE IN as that's a performance diaster for MariaDB, it now use batching to query the the relevant comment IDs via JOINs (which is not possible in a UPDATE query for SQLite) and then update them in a seperate query.
  • Resolves https://codeberg.org/forgejo/forgejo/issues/1856

- Rewrite `UpdateCommentsMigrationsByType` to not use `WHERE IN` as
that's a performance diaster for MariaDB, it now use batching to query
the the relevant comment IDs via JOINs (which is not possible in a
UPDATE query for SQLite) and then update them in a seperate query.
- Resolves https://codeberg.org/forgejo/forgejo/issues/1856
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 17, 2023
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 17, 2023
"original_author_id": 0,
})
return err
const batchSize = 50
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can first interate all the special repositories since they will not be expected too much.

@6543
Copy link
Member

6543 commented Dec 18, 2023

Instead od in would a join be more efective?

}

for _, commentID := range commentIDs {
if _, err := db.GetEngine(ctx).Table(&Comment{}).ID(commentID).Update(map[string]any{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woohoo.
This sounds like such an improvement.
Instead of one long query we now open one million db connections 😒.
SQLite, please fix your weird non-SQL conform shenanigans.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per #28500 (comment), I think we can reduce the requests times.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how that reduces the requests.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Dec 19, 2023
6543 pushed a commit that referenced this pull request Dec 21, 2023
Replace #28500

---------

Co-authored-by: Giteabot <teabot@gitea.io>
GiteaBot added a commit to GiteaBot/gitea that referenced this pull request Dec 21, 2023
Replace go-gitea#28500

---------

Co-authored-by: Giteabot <teabot@gitea.io>
lunny added a commit that referenced this pull request Dec 21, 2023
Backport #28547 by @lunny

Replace #28500

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
techknowlogick pushed a commit to techknowlogick/gitea that referenced this pull request Dec 23, 2023
Replace go-gitea#28500

---------

Co-authored-by: Giteabot <teabot@gitea.io>
fuxiaohei pushed a commit to fuxiaohei/gitea that referenced this pull request Jan 17, 2024
Replace go-gitea#28500

---------

Co-authored-by: Giteabot <teabot@gitea.io>
silverwind pushed a commit to silverwind/gitea that referenced this pull request Feb 20, 2024
Replace go-gitea#28500

---------

Co-authored-by: Giteabot <teabot@gitea.io>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 1 This PR needs approval from one additional maintainer to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants