From 6782ad2fb4a57a097b3566ba2382801b7afc8feb Mon Sep 17 00:00:00 2001 From: Dessa Simpson Date: Sat, 24 Apr 2021 13:24:39 -0700 Subject: [PATCH] Apply api dupe workaround to subscriptions endpoint --- src/cronjobs/processSubscriptions.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cronjobs/processSubscriptions.ts b/src/cronjobs/processSubscriptions.ts index 4c25524..3e250df 100644 --- a/src/cronjobs/processSubscriptions.ts +++ b/src/cronjobs/processSubscriptions.ts @@ -22,6 +22,7 @@ export async function processSubscriptions(streamer: twitch.StreamerUserIdTokenP subscriptionsArray.push(subscription.user_id as number); } insertSubscriptionQuery = insertSubscriptionQuery.slice(0,-2); // Cut last `, ` off of the end + insertSubscriptionQuery += " ON CONFLICT DO NOTHING"; // Deal with broken endpoint returning dupes var subscriptionQueryConfig = { text: insertSubscriptionQuery, values: subscriptionsArray @@ -31,9 +32,10 @@ export async function processSubscriptions(streamer: twitch.StreamerUserIdTokenP await dbconn.query(subscriptionQueryConfig); } if (response.pagination.cursor) { - //var oldFirstUserid = response.data[0].user_id; + var oldFirstUserid = response.data[0].user_id; response = await twitch.streamerApiRequest(streamer, `/subscriptions?broadcaster_id=${streamer.userid}&after=${response.pagination.cursor}&first=100`); + if (oldFirstUserid == response.data[0].user_id) break; //log(LogLevel.DEBUG,"Subscription API response:"); //log(LogLevel.DEBUG,JSON.stringify(response,null,2)); } else {