-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Prune hook_task table #11416
Prune hook_task table #11416
Conversation
…-hook-task # Conflicts: # models/migrations/migrations.go # models/migrations/v136.go
…-hook-task # Conflicts: # models/migrations/migrations.go # models/migrations/v139.go
…_purge_enabled flag
…-hook-task # Conflicts: # modules/cron/cron.go # modules/setting/cron.go
This is ready to review |
Please resolve the conflicts. |
1 similar comment
Please resolve the conflicts. |
Signed-off-by: Andrew Thornton <[email protected]>
I've resolved the conflicts. |
Thanks @zeripath |
Codecov Report
@@ Coverage Diff @@
## master #11416 +/- ##
==========================================
- Coverage 43.08% 43.07% -0.01%
==========================================
Files 658 660 +2
Lines 72448 72519 +71
==========================================
+ Hits 31211 31237 +26
- Misses 36183 36220 +37
- Partials 5054 5062 +8
Continue to review full report at Codecov.
|
no problem @bhalbright - sorry this has taken so long to merge. |
repo := bean.(*models.Repository) | ||
repoPath := repo.RepoPath() | ||
log.Trace("Running prune hook_task table on repository %s", repoPath) | ||
if err := models.DeleteDeliveredHookTasks(repo.ID, repo.NumberWebhookDeliveriesToKeep); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may fail on sqlite. I think use a Find
but not Iterate
is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I totally understand, can you elaborate? I saw Iterate usage other places like for example (if I'm understanding):
https://github.com/go-gitea/gitea/blob/master/modules/repository/check.go#L25
https://github.com/go-gitea/gitea/blob/master/modules/repository/hooks.go#L159
But I'm happy to refactor it if it is a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When did some database operations on an iterate maybe affect a lock on sqlite. If other places also have the problems, they also needs to be changed.
…-hook-task # Conflicts: # models/migrations/migrations.go # models/migrations/v148.go
@@ -245,3 +245,39 @@ func TestUpdateHookTask(t *testing.T) { | |||
assert.NoError(t, UpdateHookTask(hook)) | |||
AssertExistsAndLoadBean(t, hook) | |||
} | |||
|
|||
func TestDeleteDeliveredHookTasks_DeletesDelivered(t *testing.T) { | |||
assert.NoError(t, PrepareTestDatabase()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you insert 2 and limit to 1
and check if only the right one has been deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, I added a test where I created a new webhook that was delievered "now" and then called the delete method where 1 is kept...and then verified that the newly created webhook is still present.
@@ -39,6 +39,8 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (_ *m | |||
IsPrivate: opts.IsPrivate, | |||
IsFsckEnabled: !opts.IsMirror, | |||
CloseIssuesViaCommitInAnyBranch: setting.Repository.DefaultCloseIssuesViaCommitsInAnyBranch, | |||
IsHookTaskPurgeEnabled: setting.Repository.DefaultIsHookTaskPurgeEnabled, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we real have to set it on repo creation?
instead of use global default until user change it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I was implementing the way "CloseIssuesViaCommitInAnyBranch" is done...but I think you are suggesting that the columns added to repository would be null by default, and would only have values if the user overrides the settings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
…-hook-task # Conflicts: # models/migrations/migrations.go # models/migrations/v150.go
… will leave the most recent based if 1 delivery is to be kept
@bhalbright pleace resolve conflicts :) |
…-hook-task # Conflicts: # models/migrations/migrations.go # models/migrations/v151.go
sure, done. I started working on the changes you suggested (the columns added to repository would be null by default, and would only have values if the user overrides the settings), but I don't know that I'll have enough free time to finish it this week. |
@bhalbright thanks!!! |
…-hook-task # Conflicts: # models/migrations/migrations.go # models/migrations/v152.go # modules/repository/generate.go
@bhalbright I think bhalbright#1 should it be |
@6543 my apologies, I'm going to close this PR. I realized after chatting with @jag3773 that I misinterpreted the original ask, I should be deleting per webhook, not per repo. Also, I think I made this too complicated, the ability to override the number to keep per repo was likely overkill. I'm going to re-submit a PR that will allow you to set the values via the ini file and you will be able to cleanup via a simple age of the record or by delete all but a certain # per webhook. Also I think I'll put in an option to delete orphaned records in hook_task. I'm sorry for the time everyone spent reviewing. |
Ref issue: #10741
At a high level, added code to do regular pruning of delivered webhooks in the hook_task table. It can be turned on/off and the schedule controlled globally via app.ini. Also can be controlled per repository via UI. By default webhooks will be on and delete all but the most recent 10 deliveres.