mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-07 12:07:07 +03:00
Make db queries one request
This commit is contained in:
@@ -99,27 +99,19 @@ function sendWebhooks(userID, videoID, UUID, segmentInfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sendWebhooksNB(userID, videoID, UUID, startTime, endTime, category, probability, ytData) {
|
function sendWebhooksNB(userID, videoID, UUID, startTime, endTime, category, probability, ytData) {
|
||||||
//let submissionInfoRow = db.prepare('get', "SELECT s.videoID, s.userID, s.startTime, s.endTime, s.category, u.userName, " +
|
let submissionInfoRow = db.prepare('get', "SELECT " +
|
||||||
// "(select count(1) from sponsorTimes where userID = s.userID) count, " +
|
"(select count(1) from sponsorTimes where userID = ?) count, " +
|
||||||
// "(select count(1) from sponsorTimes where userID = s.userID and votes <= -2) disregarded " +
|
"(select count(1) from sponsorTimes where userID = ? and votes <= -2) disregarded, " +
|
||||||
// "FROM sponsorTimes s left join userNames u on s.userID = u.userID where s.userId=?",
|
"coalesce((select userName FROM userNames WHERE userID = ?), ?) userName",
|
||||||
//[userID]);
|
[userID, userID, userID, userID]);
|
||||||
let submissionCount = db.prepare('get', "SELECT COUNT(*) count FROM sponsorTimes WHERE userID=?", [userID]);
|
|
||||||
let disregardedCount = db.prepare('get', "SELECT COUNT(*) disregarded FROM sponsorTimes WHERE userID=? and votes <= -2", [userID]);
|
|
||||||
let uName = db.prepare('get', "SELECT userName FROM userNames WHERE userID=?", [userID]);
|
|
||||||
|
|
||||||
let submittedBy = "";
|
let submittedBy = "";
|
||||||
try {
|
|
||||||
// If a userName was created then show both
|
// If a userName was created then show both
|
||||||
if (uName.userName !== userID){
|
if (submissionInfoRow.userName !== userID){
|
||||||
submittedBy = uName.userName + "\n " + userID;
|
submittedBy = submissionInfoRow.userName + "\n " + userID;
|
||||||
} else {
|
} else {
|
||||||
submittedBy = userID;
|
submittedBy = userID;
|
||||||
}
|
}
|
||||||
} catch {
|
|
||||||
//Catch in case User is not in userNames table
|
|
||||||
submittedBy = userID;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send discord message
|
// Send discord message
|
||||||
if (config.discordNeuralBlockRejectWebhookURL === null) return;
|
if (config.discordNeuralBlockRejectWebhookURL === null) return;
|
||||||
@@ -133,8 +125,8 @@ function sendWebhooksNB(userID, videoID, UUID, startTime, endTime, category, pro
|
|||||||
"\n**Predicted Probability:** " + probability +
|
"\n**Predicted Probability:** " + probability +
|
||||||
"\n**Category:** " + category +
|
"\n**Category:** " + category +
|
||||||
"\n**Submitted by:** "+ submittedBy +
|
"\n**Submitted by:** "+ submittedBy +
|
||||||
"\n**Total User Submissions:** "+submissionCount.count +
|
"\n**Total User Submissions:** "+submissionInfoRow.count +
|
||||||
"\n**Ignored User Submissions:** "+disregardedCount.disregarded,
|
"\n**Ignored User Submissions:** "+submissionInfoRow.disregarded,
|
||||||
"color": 10813440,
|
"color": 10813440,
|
||||||
"thumbnail": {
|
"thumbnail": {
|
||||||
"url": ytData.items[0].snippet.thumbnails.maxres ? ytData.items[0].snippet.thumbnails.maxres.url : "",
|
"url": ytData.items[0].snippet.thumbnails.maxres ? ytData.items[0].snippet.thumbnails.maxres.url : "",
|
||||||
|
|||||||
Reference in New Issue
Block a user