summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-11-08 20:08:03 -0600
committerOmar Roth <omarroth@hotmail.com>2018-11-25 18:08:51 -0600
commit3c98601f35270fd3cf06b138de17b2c5e6919521 (patch)
tree0f499c5b141d97b676939f8997eb5e60958c568e
parent26eb59e00d9596adf69e3a3d5f8cb899f8a1da0a (diff)
downloadinvidious-3c98601f35270fd3cf06b138de17b2c5e6919521.tar.gz
invidious-3c98601f35270fd3cf06b138de17b2c5e6919521.tar.bz2
invidious-3c98601f35270fd3cf06b138de17b2c5e6919521.zip
Add job for pulling popular videos
-rw-r--r--src/invidious.cr8
-rw-r--r--src/invidious/jobs.cr15
-rw-r--r--src/invidious/users.cr2
3 files changed, 24 insertions, 1 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index cbba17c1..e1b337b5 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -14,7 +14,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-require "crypto/bcrypt/password"
require "detect_language"
require "digest/md5"
require "kemal"
@@ -112,6 +111,13 @@ spawn do
end
end
+popular_videos = [] of ChannelVideo
+spawn do
+ pull_popular_videos(PG_DB) do |videos|
+ popular_videos = videos
+ end
+end
+
decrypt_function = [] of {name: String, value: Int32}
spawn do
update_decrypt_function do |function|
diff --git a/src/invidious/jobs.cr b/src/invidious/jobs.cr
index 6f5481c9..afd0ad31 100644
--- a/src/invidious/jobs.cr
+++ b/src/invidious/jobs.cr
@@ -180,6 +180,21 @@ def pull_top_videos(config, db)
end
end
+def pull_popular_videos(db)
+ loop do
+ subscriptions = PG_DB.query_all("SELECT channel FROM \
+ (SELECT UNNEST(subscriptions) AS channel FROM users) AS d \
+ GROUP BY channel ORDER BY COUNT(channel) DESC LIMIT 40", as: String)
+
+ videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM \
+ channel_videos WHERE ucid IN (#{arg_array(subscriptions)}) \
+ ORDER BY ucid, published DESC", subscriptions, as: ChannelVideo).sort_by { |video| video.published }.reverse
+
+ yield videos
+ Fiber.yield
+ end
+end
+
def update_decrypt_function
loop do
begin
diff --git a/src/invidious/users.cr b/src/invidious/users.cr
index b7cb3fbd..28879d23 100644
--- a/src/invidious/users.cr
+++ b/src/invidious/users.cr
@@ -1,3 +1,5 @@
+require "crypto/bcrypt/password"
+
class User
module PreferencesConverter
def self.from_rs(rs)