-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
# V1 of adding personalize statuses to a user's For You Feed | ||
# Done by indiviual statuses and filtered. :foryou is the | ||
# Mammoth curated list | ||
class ForYouFeedManager | ||
include Singleton | ||
include Redisable | ||
|
||
MAX_ITEMS = 1000 | ||
MINIMUM_ENGAGMENT_ACTIONS = 2 | ||
|
||
# Adds to Account's For You Feed | ||
# We zip the statuses using the id for both the score of zadd and the value | ||
# Creating an array of array elements [["111296866514987736", "111296866514987736"]... | ||
def batch_to_feed(account_id, status_ids) | ||
statuses = status_ids.zip(status_ids) | ||
|
||
perform_push_to_feed(account_id, statuses) | ||
end | ||
|
||
private | ||
|
||
def perform_push_to_feed(account_id, statuses) | ||
foryou_key = key(account_id) | ||
redis.zadd(foryou_key, statuses) | ||
|
||
# Keep the list from growning infinitely | ||
trim(foryou_key) | ||
end | ||
|
||
# Trim a feed to maximum size by removing older items | ||
# @param [Integer] foryou_key | ||
# @return [void] | ||
def trim(foryou_key) | ||
# Remove any items past the MAX_ITEMS'th entry in our feed | ||
redis.zremrangebyrank(foryou_key, 0, -(MAX_ITEMS + 1)) | ||
end | ||
|
||
def key(account_id) | ||
FeedManager.instance.key('personal', account_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters