mirror of
https://github.com/iv-org/invidious
synced 2024-11-27 21:43:28 +01:00
Add 'views' to channel_videos
This commit is contained in:
parent
52cb239194
commit
64464f23ae
3
config/migrate-scripts/migrate-db-52cb239.sh
Executable file
3
config/migrate-scripts/migrate-db-52cb239.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
psql invidious kemal -c "ALTER TABLE channel_videos ADD COLUMN views bigint;"
|
@ -13,6 +13,7 @@ CREATE TABLE public.channel_videos
|
||||
length_seconds integer,
|
||||
live_now boolean,
|
||||
premiere_timestamp timestamp with time zone,
|
||||
views bigint,
|
||||
CONSTRAINT channel_videos_id_key UNIQUE (id)
|
||||
);
|
||||
|
||||
|
@ -2857,6 +2857,7 @@ post "/feed/webhook/:token" do |env|
|
||||
length_seconds: video.length_seconds,
|
||||
live_now: video.live_now,
|
||||
premiere_timestamp: video.premiere_timestamp,
|
||||
views: video.views,
|
||||
)
|
||||
|
||||
users = PG_DB.query_all("UPDATE users SET notifications = notifications || $1 \
|
||||
@ -2866,10 +2867,10 @@ post "/feed/webhook/:token" do |env|
|
||||
video_array = video.to_a
|
||||
args = arg_array(video_array)
|
||||
|
||||
PG_DB.exec("INSERT INTO channel_videos VALUES (#{args}) \
|
||||
PG_DB.exec("INSERT INTO channel_videos (id, title, published, updated, ucid, author, length_seconds, live_now, premiere_timestamp) VALUES (#{args}) \
|
||||
ON CONFLICT (id) DO UPDATE SET title = $2, published = $3, \
|
||||
updated = $4, ucid = $5, author = $6, length_seconds = $7, \
|
||||
live_now = $8, premiere_timestamp = $9", video_array)
|
||||
live_now = $8, premiere_timestamp = $9, views = $10", video_array)
|
||||
|
||||
users.each do |user|
|
||||
payload = {
|
||||
|
@ -24,6 +24,8 @@ struct ChannelVideo
|
||||
json.field "authorUrl", "/channel/#{self.ucid}"
|
||||
json.field "published", self.published.to_unix
|
||||
json.field "publishedText", translate(locale, "`x` ago", recode_date(self.published, locale))
|
||||
|
||||
json.field "viewCount", self.views
|
||||
end
|
||||
end
|
||||
|
||||
@ -47,6 +49,7 @@ struct ChannelVideo
|
||||
length_seconds: {type: Int32, default: 0},
|
||||
live_now: {type: Bool, default: false},
|
||||
premiere_timestamp: {type: Time?, default: nil},
|
||||
views: {type: Int64?, default: nil},
|
||||
})
|
||||
end
|
||||
|
||||
@ -155,6 +158,8 @@ def fetch_channel(ucid, db, pull_all_videos = true, locale = nil)
|
||||
updated = Time.parse_rfc3339(entry.xpath_node("updated").not_nil!.content)
|
||||
author = entry.xpath_node("author/name").not_nil!.content
|
||||
ucid = entry.xpath_node("channelid").not_nil!.content
|
||||
views = entry.xpath_node("group/community/statistics").try &.["views"]?.try &.to_i64?
|
||||
views ||= 0_i64
|
||||
|
||||
channel_video = videos.select { |video| video.id == video_id }[0]?
|
||||
|
||||
@ -175,7 +180,8 @@ def fetch_channel(ucid, db, pull_all_videos = true, locale = nil)
|
||||
author: author,
|
||||
length_seconds: length_seconds,
|
||||
live_now: live_now,
|
||||
premiere_timestamp: premiere_timestamp
|
||||
premiere_timestamp: premiere_timestamp,
|
||||
views: views,
|
||||
)
|
||||
|
||||
users = db.query_all("UPDATE users SET notifications = notifications || $1 \
|
||||
@ -190,7 +196,7 @@ def fetch_channel(ucid, db, pull_all_videos = true, locale = nil)
|
||||
db.exec("INSERT INTO channel_videos VALUES (#{args}) \
|
||||
ON CONFLICT (id) DO UPDATE SET title = $2, published = $3, \
|
||||
updated = $4, ucid = $5, author = $6, length_seconds = $7, \
|
||||
live_now = $8", video_array)
|
||||
live_now = $8, views = $10", video_array)
|
||||
|
||||
users.each do |user|
|
||||
payload = {
|
||||
@ -236,7 +242,8 @@ def fetch_channel(ucid, db, pull_all_videos = true, locale = nil)
|
||||
author: video.author,
|
||||
length_seconds: video.length_seconds,
|
||||
live_now: video.live_now,
|
||||
premiere_timestamp: video.premiere_timestamp
|
||||
premiere_timestamp: video.premiere_timestamp,
|
||||
views: video.views
|
||||
) }
|
||||
|
||||
videos.each do |video|
|
||||
@ -254,8 +261,9 @@ def fetch_channel(ucid, db, pull_all_videos = true, locale = nil)
|
||||
|
||||
# We don't update the 'premire_timestamp' here because channel pages don't include them
|
||||
db.exec("INSERT INTO channel_videos VALUES (#{args}) \
|
||||
ON CONFLICT (id) DO UPDATE SET title = $2, updated = $4, \
|
||||
ucid = $5, author = $6, length_seconds = $7, live_now = $8", video_array)
|
||||
ON CONFLICT (id) DO UPDATE SET title = $2, published = $3, \
|
||||
updated = $4, ucid = $5, author = $6, length_seconds = $7, \
|
||||
live_now = $8, views = $10", video_array)
|
||||
|
||||
# Update all users affected by insert
|
||||
users.each do |user|
|
||||
|
@ -81,7 +81,7 @@
|
||||
<% end %>
|
||||
|
||||
<div class="pure-u-1-3" style="text-align:right">
|
||||
<%= item.responds_to?(:views) ? translate(locale, "`x` views", number_to_short_text(item.views)) : "" %>
|
||||
<%= item.responds_to?(:views) && item.views ? translate(locale, "`x` views", number_to_short_text(item.views || 0)) : "" %>
|
||||
</div>
|
||||
</h5>
|
||||
<% else %>
|
||||
@ -130,7 +130,7 @@
|
||||
<% end %>
|
||||
|
||||
<div class="pure-u-1-3" style="text-align:right">
|
||||
<%= item.responds_to?(:views) ? translate(locale, "`x` views", number_to_short_text(item.views)) : "" %>
|
||||
<%= item.responds_to?(:views) && item.views ? translate(locale, "`x` views", number_to_short_text(item.views || 0)) : "" %>
|
||||
</div>
|
||||
</h5>
|
||||
<% end %>
|
||||
|
Loading…
Reference in New Issue
Block a user