mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-09 21:17:15 +03:00
minor optimizations
This commit is contained in:
@@ -128,12 +128,7 @@ async function handleGetSegments(req: Request, res: Response): Promise<searchSeg
|
||||
|
||||
const segments = await getSegmentsFromDBByVideoID(videoID, service);
|
||||
|
||||
if (segments === null || segments === undefined) {
|
||||
res.sendStatus(500);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (segments.length === 0) {
|
||||
if (!segments?.length) {
|
||||
res.sendStatus(404);
|
||||
return false;
|
||||
}
|
||||
@@ -155,6 +150,7 @@ function filterSegments(segments: DBSegment[], filters: Record<string, any>, pag
|
||||
);
|
||||
|
||||
if (sortBy !== SortableFields.timeSubmitted) {
|
||||
/* istanbul ignore next */
|
||||
filteredSegments.sort((a,b) => {
|
||||
const key = sortDir === "desc" ? 1 : -1;
|
||||
if (a[sortBy] < b[sortBy]) {
|
||||
@@ -187,6 +183,7 @@ async function endpoint(req: Request, res: Response): Promise<Response> {
|
||||
return res.send(segmentResponse);
|
||||
}
|
||||
} catch (err) {
|
||||
/* istanbul ignore next */
|
||||
if (err instanceof SyntaxError) {
|
||||
return res.status(400).send("Invalid array in parameters");
|
||||
} else return res.sendStatus(500);
|
||||
|
||||
@@ -16,7 +16,7 @@ export async function getStatus(req: Request, res: Response): Promise<Response>
|
||||
processTime = Date.now() - startTime;
|
||||
return e.value;
|
||||
})
|
||||
.catch(e => {
|
||||
.catch(e => /* istanbul ignore next */ {
|
||||
Logger.error(`status: SQL query timed out: ${e}`);
|
||||
return -1;
|
||||
});
|
||||
@@ -25,7 +25,7 @@ export async function getStatus(req: Request, res: Response): Promise<Response>
|
||||
.then(e => {
|
||||
redisProcessTime = Date.now() - startTime;
|
||||
return e;
|
||||
}).catch(e => {
|
||||
}).catch(e => /* istanbul ignore next */ {
|
||||
Logger.error(`status: redis increment timed out ${e}`);
|
||||
return [-1];
|
||||
});
|
||||
@@ -33,7 +33,7 @@ export async function getStatus(req: Request, res: Response): Promise<Response>
|
||||
|
||||
const statusValues: Record<string, any> = {
|
||||
uptime: process.uptime(),
|
||||
commit: (global as any).HEADCOMMIT || "unknown",
|
||||
commit: (global as any)?.HEADCOMMIT ?? "unknown",
|
||||
db: Number(dbVersion),
|
||||
startTime,
|
||||
processTime,
|
||||
|
||||
Reference in New Issue
Block a user