File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -152,12 +152,14 @@ def get_batch_channels(channels)
152152 return final
153153end
154154
155- def get_channel (id )
155+ def get_channel (id ) : InvidiousChannel
156156 channel = Invidious ::Database ::Channels .select(id)
157- return channel if channel
158157
159- channel = fetch_channel(id, pull_all_videos: false )
160- Invidious ::Database ::Channels .insert(channel)
158+ if channel.nil? || (Time .utc - channel.updated) > 2 .days
159+ channel = fetch_channel(id, pull_all_videos: false )
160+ Invidious ::Database ::Channels .insert(channel, update_on_conflict: true )
161+ end
162+
161163 return channel
162164end
163165
Original file line number Diff line number Diff line change @@ -10,14 +10,21 @@ module Invidious::Database::Channels
1010 # Insert / delete
1111 # -------------------
1212
13- def insert (channel : InvidiousChannel )
13+ def insert (channel : InvidiousChannel , update_on_conflict : Bool = false )
1414 channel_array = channel.to_a
1515
1616 request = <<-SQL
1717 INSERT INTO channels
1818 VALUES (#{ arg_array(channel_array) } )
1919 SQL
2020
21+ if update_on_conflict
22+ request += <<-SQL
23+ ON CONFLICT (id) DO UPDATE
24+ SET author = $2 , updated = $3
25+ SQL
26+ end
27+
2128 PG_DB .exec(request, args: channel_array)
2229 end
2330
You can’t perform that action at this time.
0 commit comments