Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
4b98e812
Commit
4b98e812
authored
Sep 06, 2016
by
Olaf Tomalka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimized event pruning query to avoid two queries.
parent
c0a92cb8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
4 deletions
+12
-4
CHANGELOG
CHANGELOG
+1
-2
app/workers/prune_old_events_worker.rb
app/workers/prune_old_events_worker.rb
+11
-2
No files found.
CHANGELOG
View file @
4b98e812
...
@@ -3,9 +3,8 @@ Please view this file on the master branch, on stable branches it's out of date.
...
@@ -3,9 +3,8 @@ Please view this file on the master branch, on stable branches it's out of date.
v 8.12.0 (unreleased)
v 8.12.0 (unreleased)
- Add ability to fork to a specific namespace using API. (ritave)
- Add ability to fork to a specific namespace using API. (ritave)
- Cleanup misalignments in Issue list view !6206
- Cleanup misalignments in Issue list view !6206
- Prune events older than 12 months.
@ritave <olaf@tomalka.me>
- Prune events older than 12 months.
(ritave)
- Prepend blank line to `Closes` message on merge request linked to issue (lukehowell)
- Prepend blank line to `Closes` message on merge request linked to issue (lukehowell)
- Prune events older than 12 months.
- Filter tags by name !6121
- Filter tags by name !6121
- Make push events have equal vertical spacing.
- Make push events have equal vertical spacing.
- Add two-factor recovery endpoint to internal API !5510
- Add two-factor recovery endpoint to internal API !5510
...
...
app/workers/prune_old_events_worker.rb
View file @
4b98e812
...
@@ -2,7 +2,16 @@ class PruneOldEventsWorker
...
@@ -2,7 +2,16 @@ class PruneOldEventsWorker
include
Sidekiq
::
Worker
include
Sidekiq
::
Worker
def
perform
def
perform
# Contribution calendar shows maximum 12 months of events
# Contribution calendar shows maximum 12 months of events.
Event
.
delete
(
Event
.
unscoped
.
where
(
'created_at < ?'
,
(
12
.
months
+
1
.
day
).
ago
).
limit
(
10_000
).
pluck
(
:id
))
# Double nested query is used because MySQL doesn't allow DELETE subqueries
# on the same table.
Event
.
unscoped
.
where
(
'(id IN (SELECT id FROM (?) ids_to_remove))'
,
Event
.
unscoped
.
where
(
'created_at < ?'
,
(
12
.
months
+
1
.
day
).
ago
).
select
(
:id
).
limit
(
10_000
)).
delete_all
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment