Skip to content

Commit 27f7b6d

Browse files
committed
Add chapter category & action type to getUserStats.ts
This also fixes chapters not being counted in the segment counts.
1 parent ea05284 commit 27f7b6d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/routes/getUserStats.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ async function dbGetUserSummary(userID: HashedUserID, fetchCategoryStats: boolea
2121
SUM(CASE WHEN "category" = 'poi_highlight' THEN 1 ELSE 0 END) as "categorySumHighlight",
2222
SUM(CASE WHEN "category" = 'filler' THEN 1 ELSE 0 END) as "categorySumFiller",
2323
SUM(CASE WHEN "category" = 'exclusive_access' THEN 1 ELSE 0 END) as "categorySumExclusiveAccess",
24+
SUM(CASE WHEN "category" = 'chapter' THEN 1 ELSE 0 END) as "categorySumChapter",
2425
`;
2526
}
2627
if (fetchActionTypeStats) {
@@ -29,15 +30,16 @@ async function dbGetUserSummary(userID: HashedUserID, fetchCategoryStats: boolea
2930
SUM(CASE WHEN "actionType" = 'mute' THEN 1 ELSE 0 END) as "typeSumMute",
3031
SUM(CASE WHEN "actionType" = 'full' THEN 1 ELSE 0 END) as "typeSumFull",
3132
SUM(CASE WHEN "actionType" = 'poi' THEN 1 ELSE 0 END) as "typeSumPoi",
33+
SUM(CASE WHEN "actionType" = 'chapter' THEN 1 ELSE 0 END) as "typeSumChapter",
3234
`;
3335
}
3436
try {
3537
const row = await db.prepare("get", `
36-
SELECT SUM(((CASE WHEN "endTime" - "startTime" > ? THEN ? ELSE "endTime" - "startTime" END) / 60) * "views") as "minutesSaved",
38+
SELECT SUM(CASE WHEN "actionType" = 'chapter' THEN 0 ELSE ((CASE WHEN "endTime" - "startTime" > ? THEN ? ELSE "endTime" - "startTime" END) / 60) * "views" END) as "minutesSaved",
3739
${additionalQuery}
3840
count(*) as "segmentCount"
3941
FROM "sponsorTimes"
40-
WHERE "userID" = ? AND "votes" > -2 AND "shadowHidden" != 1 AND "actionType" != 'chapter'`,
42+
WHERE "userID" = ? AND "votes" > -2 AND "shadowHidden" != 1`,
4143
[maxRewardTimePerSegmentInSeconds, maxRewardTimePerSegmentInSeconds, userID]);
4244
const source = (row.minutesSaved != null) ? row : {};
4345
const handler = { get: (target: Record<string, any>, name: string) => target?.[name] || 0 };
@@ -60,14 +62,16 @@ async function dbGetUserSummary(userID: HashedUserID, fetchCategoryStats: boolea
6062
poi_highlight: proxy.categorySumHighlight,
6163
filler: proxy.categorySumFiller,
6264
exclusive_access: proxy.categorySumExclusiveAccess,
65+
chapter: proxy.categorySumChapter,
6366
};
6467
}
6568
if (fetchActionTypeStats) {
6669
result.actionTypeCount = {
6770
skip: proxy.typeSumSkip,
6871
mute: proxy.typeSumMute,
6972
full: proxy.typeSumFull,
70-
poi: proxy.typeSumPoi
73+
poi: proxy.typeSumPoi,
74+
chapter: proxy.typeSumChapter,
7175
};
7276
}
7377
return result;

0 commit comments

Comments
 (0)