mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-09 21:17:15 +03:00
@@ -262,7 +262,7 @@ async function chooseSegments(videoID: VideoID, service: Service, segments: DBSe
|
|||||||
const fetchData = async () => await buildSegmentGroups(segments);
|
const fetchData = async () => await buildSegmentGroups(segments);
|
||||||
|
|
||||||
const groups = useCache
|
const groups = useCache
|
||||||
? await QueryCacher.get(fetchData, skipSegmentGroupsKey(videoID, service), false)
|
? await QueryCacher.get(fetchData, skipSegmentGroupsKey(videoID, service))
|
||||||
: await fetchData();
|
: await fetchData();
|
||||||
|
|
||||||
// Filter for only 1 item for POI categories and Full video
|
// Filter for only 1 item for POI categories and Full video
|
||||||
@@ -337,7 +337,7 @@ async function buildSegmentGroups(segments: DBSegment[]): Promise<OverlappingSeg
|
|||||||
function splitPercentOverlap(groups: OverlappingSegmentGroup[]): OverlappingSegmentGroup[] {
|
function splitPercentOverlap(groups: OverlappingSegmentGroup[]): OverlappingSegmentGroup[] {
|
||||||
return groups.flatMap((group) => {
|
return groups.flatMap((group) => {
|
||||||
const result: OverlappingSegmentGroup[] = [];
|
const result: OverlappingSegmentGroup[] = [];
|
||||||
for (const segment of group.segments) {
|
group.segments.forEach((segment) => {
|
||||||
const bestGroup = result.find((group) => {
|
const bestGroup = result.find((group) => {
|
||||||
// At least one segment in the group must have high % overlap or the same action type
|
// At least one segment in the group must have high % overlap or the same action type
|
||||||
// Since POI and Full video segments will always have <= 0 overlap, they will always be in their own groups
|
// Since POI and Full video segments will always have <= 0 overlap, they will always be in their own groups
|
||||||
@@ -360,7 +360,7 @@ function splitPercentOverlap(groups: OverlappingSegmentGroup[]): OverlappingSegm
|
|||||||
} else {
|
} else {
|
||||||
result.push({ segments: [segment], votes: segment.votes, reputation: segment.reputation, locked: segment.locked, required: segment.required });
|
result.push({ segments: [segment], votes: segment.votes, reputation: segment.reputation, locked: segment.locked, required: segment.required });
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { skipSegmentsHashKey, skipSegmentsKey, reputationKey, ratingHashKey, ski
|
|||||||
import { Service, VideoID, VideoIDHash } from "../types/segments.model";
|
import { Service, VideoID, VideoIDHash } from "../types/segments.model";
|
||||||
import { Feature, HashedUserID, UserID } from "../types/user.model";
|
import { Feature, HashedUserID, UserID } from "../types/user.model";
|
||||||
|
|
||||||
async function get<T>(fetchFromDB: () => Promise<T>, key: string, cacheEmpty = true): Promise<T> {
|
async function get<T>(fetchFromDB: () => Promise<T>, key: string): Promise<T> {
|
||||||
try {
|
try {
|
||||||
const reply = await redis.get(key);
|
const reply = await redis.get(key);
|
||||||
if (reply) {
|
if (reply) {
|
||||||
@@ -16,9 +16,7 @@ async function get<T>(fetchFromDB: () => Promise<T>, key: string, cacheEmpty = t
|
|||||||
|
|
||||||
const data = await fetchFromDB();
|
const data = await fetchFromDB();
|
||||||
|
|
||||||
if (cacheEmpty || data) {
|
|
||||||
redis.set(key, JSON.stringify(data)).catch((err) => Logger.error(err));
|
redis.set(key, JSON.stringify(data)).catch((err) => Logger.error(err));
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user