Skip to content

Commit 0b9e702

Browse files
committed
minor optimizations
1 parent 9ef0eaf commit 0b9e702

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/routes/getSearchSegments.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,7 @@ async function handleGetSegments(req: Request, res: Response): Promise<searchSeg
128128

129129
const segments = await getSegmentsFromDBByVideoID(videoID, service);
130130

131-
if (segments === null || segments === undefined) {
132-
res.sendStatus(500);
133-
return false;
134-
}
135-
136-
if (segments.length === 0) {
131+
if (!segments?.length) {
137132
res.sendStatus(404);
138133
return false;
139134
}
@@ -155,6 +150,7 @@ function filterSegments(segments: DBSegment[], filters: Record<string, any>, pag
155150
);
156151

157152
if (sortBy !== SortableFields.timeSubmitted) {
153+
/* istanbul ignore next */
158154
filteredSegments.sort((a,b) => {
159155
const key = sortDir === "desc" ? 1 : -1;
160156
if (a[sortBy] < b[sortBy]) {
@@ -187,6 +183,7 @@ async function endpoint(req: Request, res: Response): Promise<Response> {
187183
return res.send(segmentResponse);
188184
}
189185
} catch (err) {
186+
/* istanbul ignore next */
190187
if (err instanceof SyntaxError) {
191188
return res.status(400).send("Invalid array in parameters");
192189
} else return res.sendStatus(500);

src/routes/getStatus.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export async function getStatus(req: Request, res: Response): Promise<Response>
1616
processTime = Date.now() - startTime;
1717
return e.value;
1818
})
19-
.catch(e => {
19+
.catch(e => /* istanbul ignore next */ {
2020
Logger.error(`status: SQL query timed out: ${e}`);
2121
return -1;
2222
});
@@ -25,15 +25,15 @@ export async function getStatus(req: Request, res: Response): Promise<Response>
2525
.then(e => {
2626
redisProcessTime = Date.now() - startTime;
2727
return e;
28-
}).catch(e => {
28+
}).catch(e => /* istanbul ignore next */ {
2929
Logger.error(`status: redis increment timed out ${e}`);
3030
return [-1];
3131
});
3232
statusRequests = numberRequests?.[0];
3333

3434
const statusValues: Record<string, any> = {
3535
uptime: process.uptime(),
36-
commit: (global as any).HEADCOMMIT || "unknown",
36+
commit: (global as any)?.HEADCOMMIT ?? "unknown",
3737
db: Number(dbVersion),
3838
startTime,
3939
processTime,

0 commit comments

Comments
 (0)