Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
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
Show more breadcrumbs
Pierre Boudes
mastodon
Commits
96702e7f
Unverified
Commit
96702e7f
authored
5 years ago
by
Eugen Rochko
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add `tootctl cache recount` command (#11597)
parent
8a555534
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/models/concerns/account_counters.rb
+2
-1
2 additions, 1 deletion
app/models/concerns/account_counters.rb
app/models/status.rb
+5
-2
5 additions, 2 deletions
app/models/status.rb
lib/mastodon/cache_cli.rb
+45
-0
45 additions, 0 deletions
lib/mastodon/cache_cli.rb
with
52 additions
and
3 deletions
app/models/concerns/account_counters.rb
+
2
−
1
View file @
96702e7f
...
...
@@ -26,7 +26,8 @@ module AccountCounters
private
def
save_account_stat
return
unless
account_stat
&
.
changed?
return
unless
association
(
:account_stat
).
loaded?
&&
account_stat
&
.
changed?
account_stat
.
save
end
end
This diff is collapsed.
Click to expand it.
app/models/status.rb
+
5
−
2
View file @
96702e7f
...
...
@@ -388,13 +388,16 @@ class Status < ApplicationRecord
end
end
def
status_stat
super
||
build_status_stat
end
private
def
update_status_stat!
(
attrs
)
return
if
marked_for_destruction?
||
destroyed?
record
=
status_stat
||
build_status_stat
record
.
update
(
attrs
)
status_stat
.
update
(
attrs
)
end
def
store_uri
...
...
This diff is collapsed.
Click to expand it.
lib/mastodon/cache_cli.rb
+
45
−
0
View file @
96702e7f
...
...
@@ -15,5 +15,50 @@ module Mastodon
Rails
.
cache
.
clear
say
(
'OK'
,
:green
)
end
desc
'recount TYPE'
,
'Update hard-cached counters'
long_desc
<<~
LONG_DESC
Update hard-cached counters of TYPE by counting referenced
records from scratch. TYPE can be "accounts" or "statuses".
It may take a very long time to finish, depending on the
size of the database.
LONG_DESC
def
recount
(
type
)
processed
=
0
case
type
when
'accounts'
Account
.
local
.
includes
(
:account_stat
).
find_each
do
|
account
|
account_stat
=
account
.
account_stat
account_stat
.
following_count
=
account
.
active_relationships
.
count
account_stat
.
followers_count
=
account
.
passive_relationships
.
count
account_stat
.
statuses_count
=
account
.
statuses
.
where
.
not
(
visibility: :direct
).
count
account_stat
.
save
if
account_stat
.
changed?
processed
+=
1
say
(
'.'
,
:green
,
false
)
end
when
'statuses'
Status
.
includes
(
:status_stat
).
find_each
do
|
status
|
status_stat
=
status
.
status_stat
status_stat
.
replies_count
=
status
.
replies
.
where
.
not
(
visibility: :direct
).
count
status_stat
.
reblogs_count
=
status
.
reblogs
.
count
status_stat
.
favourites_count
=
status
.
favourites
.
count
status_stat
.
save
if
status_stat
.
changed?
processed
+=
1
say
(
'.'
,
:green
,
false
)
end
else
say
(
"Unknown type:
#{
type
}
"
,
:red
)
exit
(
1
)
end
say
say
(
"OK, recounted
#{
processed
}
records"
,
:green
)
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