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
d68868ca
Unverified
Commit
d68868ca
authored
7 years ago
by
Eugen Rochko
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Lists redis clean-up (#5886)
* When list is deleted, remove feed from redis * Clean up list feeds of inactive users
parent
e20895f2
No related branches found
Branches containing commit
Tags
v1.6.0rc2
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/list.rb
+19
-0
19 additions, 0 deletions
app/models/list.rb
app/workers/scheduler/feed_cleanup_scheduler.rb
+30
-10
30 additions, 10 deletions
app/workers/scheduler/feed_cleanup_scheduler.rb
with
49 additions
and
10 deletions
app/models/list.rb
+
19
−
0
View file @
d68868ca
...
...
@@ -19,4 +19,23 @@ class List < ApplicationRecord
has_many
:accounts
,
through: :list_accounts
validates
:title
,
presence:
true
before_destroy
:clean_feed_manager
private
def
clean_feed_manager
reblog_key
=
FeedManager
.
instance
.
key
(
:list
,
id
,
'reblogs'
)
reblogged_id_set
=
Redis
.
current
.
zrange
(
reblog_key
,
0
,
-
1
)
Redis
.
current
.
pipelined
do
Redis
.
current
.
del
(
FeedManager
.
instance
.
key
(
:list
,
id
))
Redis
.
current
.
del
(
reblog_key
)
reblogged_id_set
.
each
do
|
reblogged_id
|
reblog_set_key
=
FeedManager
.
instance
.
key
(
:list
,
id
,
"reblogs:
#{
reblogged_id
}
"
)
Redis
.
current
.
del
(
reblog_set_key
)
end
end
end
end
This diff is collapsed.
Click to expand it.
app/workers/scheduler/feed_cleanup_scheduler.rb
+
30
−
10
View file @
d68868ca
...
...
@@ -5,16 +5,30 @@ class Scheduler::FeedCleanupScheduler
include
Sidekiq
::
Worker
def
perform
clean_home_feeds!
clean_list_feeds!
end
private
def
clean_home_feeds!
clean_feeds!
(
inactive_account_ids
,
:home
)
end
def
clean_list_feeds!
clean_feeds!
(
inactive_list_ids
,
:list
)
end
def
clean_feeds!
(
ids
,
type
)
reblogged_id_sets
=
{}
feedmanager
=
FeedManager
.
instance
redis
.
pipelined
do
inactive_user_
ids
.
each
do
|
account
_id
|
redis
.
del
(
feedmanager
.
key
(
:home
,
account
_id
))
reblog_key
=
feedmanager
.
key
(
:home
,
account
_id
,
'reblogs'
)
ids
.
each
do
|
feed
_id
|
redis
.
del
(
feed
_
manager
.
key
(
type
,
feed
_id
))
reblog_key
=
feed
_
manager
.
key
(
type
,
feed
_id
,
'reblogs'
)
# We collect a future for this: we don't block while getting
# it, but we can iterate over it later.
reblogged_id_sets
[
account
_id
]
=
redis
.
zrange
(
reblog_key
,
0
,
-
1
)
reblogged_id_sets
[
feed
_id
]
=
redis
.
zrange
(
reblog_key
,
0
,
-
1
)
redis
.
del
(
reblog_key
)
end
end
...
...
@@ -22,19 +36,25 @@ class Scheduler::FeedCleanupScheduler
# Remove all of the reblog tracking keys we just removed the
# references to.
redis
.
pipelined
do
reblogged_id_sets
.
each
do
|
account
_id
,
future
|
reblogged_id_sets
.
each
do
|
feed
_id
,
future
|
future
.
value
.
each
do
|
reblogged_id
|
reblog_set_key
=
feedmanager
.
key
(
:home
,
account
_id
,
"reblogs:
#{
reblogged_id
}
"
)
reblog_set_key
=
feed
_
manager
.
key
(
type
,
feed
_id
,
"reblogs:
#{
reblogged_id
}
"
)
redis
.
del
(
reblog_set_key
)
end
end
end
end
private
def
inactive_account_ids
@inactive_account_ids
||=
User
.
confirmed
.
inactive
.
pluck
(
:account_id
)
end
def
inactive_list_ids
List
.
where
(
account_id:
inactive_account_ids
).
pluck
(
:id
)
end
def
inactive_user_ids
@inactive_user_ids
||=
User
.
confirmed
.
inactive
.
pluck
(
:account_id
)
def
feed_manager
FeedManager
.
instance
end
def
redis
...
...
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