Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Mastodon
Commits
60b9fa64
Unverified
Commit
60b9fa64
authored
1 year ago
by
Claire
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix cached posts including stale stats (#26409)
parent
3ed2bf92
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/status.rb
+12
-0
12 additions, 0 deletions
app/models/status.rb
spec/controllers/concerns/cache_concern_spec.rb
+22
-2
22 additions, 2 deletions
spec/controllers/concerns/cache_concern_spec.rb
with
34 additions
and
2 deletions
app/models/status.rb
+
12
−
0
View file @
60b9fa64
...
...
@@ -367,13 +367,25 @@ class Status < ApplicationRecord
account_ids
.
uniq!
status_ids
=
cached_items
.
map
{
|
item
|
item
.
reblog?
?
item
.
reblog_of_id
:
item
.
id
}.
uniq
return
if
account_ids
.
empty?
accounts
=
Account
.
where
(
id:
account_ids
).
includes
(
:account_stat
,
:user
).
index_by
(
&
:id
)
status_stats
=
StatusStat
.
where
(
status_id:
status_ids
).
index_by
(
&
:status_id
)
cached_items
.
each
do
|
item
|
item
.
account
=
accounts
[
item
.
account_id
]
item
.
reblog
.
account
=
accounts
[
item
.
reblog
.
account_id
]
if
item
.
reblog?
if
item
.
reblog?
status_stat
=
status_stats
[
item
.
reblog
.
id
]
item
.
reblog
.
status_stat
=
status_stat
if
status_stat
.
present?
else
status_stat
=
status_stats
[
item
.
id
]
item
.
status_stat
=
status_stat
if
status_stat
.
present?
end
end
end
...
...
This diff is collapsed.
Click to expand it.
spec/controllers/concerns/cache_concern_spec.rb
+
22
−
2
View file @
60b9fa64
...
...
@@ -13,12 +13,17 @@ RSpec.describe CacheConcern do
def
empty_relation
render
plain:
cache_collection
(
Status
.
none
,
Status
).
size
end
def
account_statuses_favourites
render
plain:
cache_collection
(
Status
.
where
(
account_id:
params
[
:id
]),
Status
).
map
(
&
:favourites_count
)
end
end
before
do
routes
.
draw
do
get
'empty_array'
=>
'anonymous#empty_array'
post
'empty_relation'
=>
'anonymous#empty_relation'
get
'empty_array'
=>
'anonymous#empty_array'
get
'empty_relation'
=>
'anonymous#empty_relation'
get
'account_statuses_favourites'
=>
'anonymous#account_statuses_favourites'
end
end
...
...
@@ -36,5 +41,20 @@ RSpec.describe CacheConcern do
expect
(
response
.
body
).
to
eq
'0'
end
end
context
'when given a collection of statuses'
do
let!
(
:account
)
{
Fabricate
(
:account
)
}
let!
(
:status
)
{
Fabricate
(
:status
,
account:
account
)
}
it
'correctly updates with new interactions'
do
get
:account_statuses_favourites
,
params:
{
id:
account
.
id
}
expect
(
response
.
body
).
to
eq
'[0]'
FavouriteService
.
new
.
call
(
account
,
status
)
get
:account_statuses_favourites
,
params:
{
id:
account
.
id
}
expect
(
response
.
body
).
to
eq
'[1]'
end
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