diff options
| author | Omar Roth <omarroth@hotmail.com> | 2018-11-08 16:43:28 -0600 |
|---|---|---|
| committer | Omar Roth <omarroth@hotmail.com> | 2018-11-08 16:43:28 -0600 |
| commit | c5d2a57206f01706391c8d19a2d78a711af59621 (patch) | |
| tree | 2f5478edf428c7be75eec3b5a4c45c4a7430885d /src | |
| parent | 6ae5d489ec26a23a7e0070967405b0b71278fe05 (diff) | |
| download | invidious-c5d2a57206f01706391c8d19a2d78a711af59621.tar.gz invidious-c5d2a57206f01706391c8d19a2d78a711af59621.tar.bz2 invidious-c5d2a57206f01706391c8d19a2d78a711af59621.zip | |
Speed up importing watch history
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious.cr | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/invidious.cr b/src/invidious.cr index ab133ef7..72eb260a 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -1228,17 +1228,14 @@ post "/data_control" do |env| end end - body["watch_history"]?.try &.as_a.each do |id| - id = id.as_s - - if !user.watched.includes? id - PG_DB.exec("UPDATE users SET watched = array_append(watched,$1) WHERE email = $2", id, user.email) - user.watched << id - end + if body["watch_history"]? + watched = user.watched + body["watch_history"].as_a.map { |a| a.as_s } + watched.uniq! + PG_DB.exec("UPDATE users SET watched = $1 WHERE email = $2", watched, user.email) end if body["preferences"]? - PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", body["preferences"].to_json, user.email) + PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", body["preferences"].to_json, user.email) end when "import_youtube" subscriptions = XML.parse(body) |
