Prevent duplicate subscriptions when importing user data

pull/733/head
Omar Roth 6 years ago
parent 650b44ade2
commit e14f2f2750

@ -1116,7 +1116,7 @@ post "/data_control" do |env|
body["subscriptions"].as_a.each do |ucid| body["subscriptions"].as_a.each do |ucid|
ucid = ucid.as_s ucid = ucid.as_s
if !user.subscriptions.includes? ucid if !user.subscriptions.includes? ucid
PG_DB.exec("UPDATE users SET subscriptions = array_append(subscriptions,$1) WHERE id = $2", ucid, user.id) PG_DB.exec("UPDATE users SET subscriptions = array_append(subscriptions,$1) WHERE email = $2", ucid, user.email)
begin begin
client = make_client(YT_URL) client = make_client(YT_URL)
@ -1131,6 +1131,7 @@ post "/data_control" do |env|
id = id.as_s id = id.as_s
if !user.watched.includes? id if !user.watched.includes? id
PG_DB.exec("UPDATE users SET watched = array_append(watched,$1) WHERE email = $2", id, user.email) PG_DB.exec("UPDATE users SET watched = array_append(watched,$1) WHERE email = $2", id, user.email)
user.watched << id
end end
end end
@ -1141,11 +1142,12 @@ post "/data_control" do |env|
ucid = channel["xmlUrl"].match(/UC[a-zA-Z0-9_-]{22}/).not_nil![0] ucid = channel["xmlUrl"].match(/UC[a-zA-Z0-9_-]{22}/).not_nil![0]
if !user.subscriptions.includes? ucid if !user.subscriptions.includes? ucid
PG_DB.exec("UPDATE users SET subscriptions = array_append(subscriptions,$1) WHERE email = $2", ucid, user.email)
begin begin
client = make_client(YT_URL) client = make_client(YT_URL)
get_channel(ucid, client, PG_DB, false, false) get_channel(ucid, client, PG_DB, false, false)
PG_DB.exec("UPDATE users SET subscriptions = array_append(subscriptions,$1) WHERE email = $2", ucid, user.email)
user.subscriptions << ucid
rescue ex rescue ex
next next
end end
@ -1156,11 +1158,12 @@ post "/data_control" do |env|
ucid = md["channel_id"] ucid = md["channel_id"]
if !user.subscriptions.includes? ucid if !user.subscriptions.includes? ucid
PG_DB.exec("UPDATE users SET subscriptions = array_append(subscriptions,$1) WHERE email = $2", ucid, user.email)
begin begin
client = make_client(YT_URL) client = make_client(YT_URL)
get_channel(ucid, client, PG_DB, false, false) get_channel(ucid, client, PG_DB, false, false)
PG_DB.exec("UPDATE users SET subscriptions = array_append(subscriptions,$1) WHERE email = $2", ucid, user.email)
user.subscriptions << ucid
rescue ex rescue ex
next next
end end
@ -1192,19 +1195,22 @@ post "/data_control" do |env|
db = entry.io.gets_to_end db = entry.io.gets_to_end
db.scan(/youtube\.com\/watch\?v\=(?<id>[a-zA-Z0-9_-]{11})/) do |md| db.scan(/youtube\.com\/watch\?v\=(?<id>[a-zA-Z0-9_-]{11})/) do |md|
if !user.watched.includes? md["id"] id = md["id"]
PG_DB.exec("UPDATE users SET watched = array_append(watched,$1) WHERE email = $2", md["id"], user.email) 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 end
end end
db.scan(/youtube\.com\/channel\/(?<ucid>[a-zA-Z0-9_-]{22})/) do |md| db.scan(/youtube\.com\/channel\/(?<ucid>[a-zA-Z0-9_-]{22})/) do |md|
ucid = md["ucid"] ucid = md["ucid"]
if !user.subscriptions.includes? ucid if !user.subscriptions.includes? ucid
PG_DB.exec("UPDATE users SET subscriptions = array_append(subscriptions,$1) WHERE email = $2", ucid, user.email)
begin begin
client = make_client(YT_URL) client = make_client(YT_URL)
get_channel(ucid, client, PG_DB, false, false) get_channel(ucid, client, PG_DB, false, false)
PG_DB.exec("UPDATE users SET subscriptions = array_append(subscriptions,$1) WHERE email = $2", ucid, user.email)
user.subscriptions << ucid
rescue ex rescue ex
next next
end end

Loading…
Cancel
Save