Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mastofe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Pleroma
mastofe
Commits
188cddef
Commit
188cddef
authored
8 years ago
by
Eugen Rochko
Browse files
Options
Downloads
Patches
Plain Diff
Add maintenance task for updating counter caches
parent
3ac44551
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/tasks/mastodon.rake
+19
-0
19 additions, 0 deletions
lib/tasks/mastodon.rake
with
19 additions
and
0 deletions
lib/tasks/mastodon.rake
+
19
−
0
View file @
188cddef
...
...
@@ -62,4 +62,23 @@ namespace :mastodon do
end
end
end
namespace
:maintenance
do
desc
'Update counter caches'
task
update_counter_caches: :environment
do
Rails
.
logger
.
debug
'Updating counter caches for accounts...'
Account
.
unscoped
.
select
(
'id'
).
find_in_batches
do
|
batch
|
Account
.
where
(
id:
batch
.
map
(
&
:id
)).
update_all
(
'statuses_count = (select count(*) from statuses where account_id = accounts.id), followers_count = (select count(*) from follows where target_account_id = accounts.id), following_count = (select count(*) from follows where account_id = accounts.id)'
)
end
Rails
.
logger
.
debug
'Updating counter caches for statuses...'
Status
.
unscoped
.
select
(
'id'
).
find_in_batches
do
|
batch
|
Status
.
where
(
id:
batch
.
map
(
&
:id
)).
update_all
(
'favourites_count = (select count(*) from favourites where favourites.status_id = statuses.id), reblogs_count = (select count(*) from statuses as reblogs where reblogs.reblog_of_id = statuses.id)'
)
end
Rails
.
logger
.
debug
'Done!'
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment