mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-08-14.git
synced 2024-08-15 00:53:20 +00:00
Add proper queuing for feed events
This commit is contained in:
parent
de77c71042
commit
3ac766530d
1 changed files with 14 additions and 4 deletions
|
@ -45,13 +45,14 @@ end
|
||||||
def refresh_feeds(db, logger, max_threads = 1, use_feed_events = false)
|
def refresh_feeds(db, logger, max_threads = 1, use_feed_events = false)
|
||||||
max_channel = Channel(Int32).new
|
max_channel = Channel(Int32).new
|
||||||
|
|
||||||
# TODO: Instead of Fiber.yield, use proper queuing to prevent overloading DB
|
|
||||||
# Spawn thread to handle feed events
|
# Spawn thread to handle feed events
|
||||||
if use_feed_events
|
if use_feed_events
|
||||||
|
queue = Deque(String).new(30)
|
||||||
|
|
||||||
spawn do
|
spawn do
|
||||||
PG.connect_listen(PG_URL, "feeds") do |event|
|
loop do
|
||||||
spawn do
|
if event = queue.shift?
|
||||||
feed = JSON.parse(event.payload)
|
feed = JSON.parse(event)
|
||||||
email = feed["email"].as_s
|
email = feed["email"].as_s
|
||||||
action = feed["action"].as_s
|
action = feed["action"].as_s
|
||||||
|
|
||||||
|
@ -61,11 +62,20 @@ def refresh_feeds(db, logger, max_threads = 1, use_feed_events = false)
|
||||||
when "refresh"
|
when "refresh"
|
||||||
db.exec("REFRESH MATERIALIZED VIEW #{view_name}")
|
db.exec("REFRESH MATERIALIZED VIEW #{view_name}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Delete any future events that we just processed
|
||||||
|
queue.delete(event)
|
||||||
|
else
|
||||||
|
sleep 1.second
|
||||||
end
|
end
|
||||||
|
|
||||||
Fiber.yield
|
Fiber.yield
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
PG.connect_listen(PG_URL, "feeds") do |event|
|
||||||
|
queue << event.payload
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
spawn do
|
spawn do
|
||||||
|
|
Loading…
Reference in a new issue