Fix: properly handle timeline db errors

This commit is contained in:
April John 2023-05-05 14:30:08 +02:00
parent 7c1e1d336f
commit 5fd6690755
6 changed files with 88 additions and 30 deletions

View file

@ -32,6 +32,11 @@ export const meta = {
code: "GTL_DISABLED", code: "GTL_DISABLED",
id: "0332fc13-6ab2-4427-ae80-a9fadffd1a6b", id: "0332fc13-6ab2-4427-ae80-a9fadffd1a6b",
}, },
queryError: {
message: "Please follow more users.",
code: "QUERY_ERROR",
id: "620763f4-f621-4533-ab33-0577a1a3c343",
},
}, },
} as const; } as const;
@ -106,12 +111,16 @@ export default define(meta, paramDef, async (ps, user) => {
const found = []; const found = [];
const take = Math.floor(ps.limit * 1.5); const take = Math.floor(ps.limit * 1.5);
let skip = 0; let skip = 0;
try {
while (found.length < ps.limit) { while (found.length < ps.limit) {
const notes = await query.take(take).skip(skip).getMany(); const notes = await query.take(take).skip(skip).getMany();
found.push(...(await Notes.packMany(notes, user))); found.push(...(await Notes.packMany(notes, user)));
skip += take; skip += take;
if (notes.length < take) break; if (notes.length < take) break;
} }
} catch (error) {
throw new ApiError(meta.errors.queryError);
}
if (found.length > ps.limit) { if (found.length > ps.limit) {
found.length = ps.limit; found.length = ps.limit;

View file

@ -36,6 +36,11 @@ export const meta = {
code: "STL_DISABLED", code: "STL_DISABLED",
id: "620763f4-f621-4533-ab33-0577a1a3c342", id: "620763f4-f621-4533-ab33-0577a1a3c342",
}, },
queryError: {
message: "Please follow more users.",
code: "QUERY_ERROR",
id: "620763f4-f621-4533-ab33-0577a1a3c343",
},
}, },
} as const; } as const;
@ -162,12 +167,16 @@ export default define(meta, paramDef, async (ps, user) => {
const found = []; const found = [];
const take = Math.floor(ps.limit * 1.5); const take = Math.floor(ps.limit * 1.5);
let skip = 0; let skip = 0;
try {
while (found.length < ps.limit) { while (found.length < ps.limit) {
const notes = await query.take(take).skip(skip).getMany(); const notes = await query.take(take).skip(skip).getMany();
found.push(...(await Notes.packMany(notes, user))); found.push(...(await Notes.packMany(notes, user)));
skip += take; skip += take;
if (notes.length < take) break; if (notes.length < take) break;
} }
} catch (error) {
throw new ApiError(meta.errors.queryError);
}
if (found.length > ps.limit) { if (found.length > ps.limit) {
found.length = ps.limit; found.length = ps.limit;

View file

@ -35,6 +35,11 @@ export const meta = {
code: "LTL_DISABLED", code: "LTL_DISABLED",
id: "45a6eb02-7695-4393-b023-dd3be9aaaefd", id: "45a6eb02-7695-4393-b023-dd3be9aaaefd",
}, },
queryError: {
message: "Please follow more users.",
code: "QUERY_ERROR",
id: "620763f4-f621-4533-ab33-0577a1a3c343",
},
}, },
} as const; } as const;
@ -136,12 +141,16 @@ export default define(meta, paramDef, async (ps, user) => {
const found = []; const found = [];
const take = Math.floor(ps.limit * 1.5); const take = Math.floor(ps.limit * 1.5);
let skip = 0; let skip = 0;
try {
while (found.length < ps.limit) { while (found.length < ps.limit) {
const notes = await query.take(take).skip(skip).getMany(); const notes = await query.take(take).skip(skip).getMany();
found.push(...(await Notes.packMany(notes, user))); found.push(...(await Notes.packMany(notes, user)));
skip += take; skip += take;
if (notes.length < take) break; if (notes.length < take) break;
} }
} catch (error) {
throw new ApiError(meta.errors.queryError);
}
if (found.length > ps.limit) { if (found.length > ps.limit) {
found.length = ps.limit; found.length = ps.limit;

View file

@ -35,6 +35,11 @@ export const meta = {
code: "RTL_DISABLED", code: "RTL_DISABLED",
id: "45a6eb02-7695-4393-b023-dd3be9aaaefe", id: "45a6eb02-7695-4393-b023-dd3be9aaaefe",
}, },
queryError: {
message: "Please follow more users.",
code: "QUERY_ERROR",
id: "620763f4-f621-4533-ab33-0577a1a3c343",
},
}, },
} as const; } as const;
@ -139,12 +144,16 @@ export default define(meta, paramDef, async (ps, user) => {
const found = []; const found = [];
const take = Math.floor(ps.limit * 1.5); const take = Math.floor(ps.limit * 1.5);
let skip = 0; let skip = 0;
try {
while (found.length < ps.limit) { while (found.length < ps.limit) {
const notes = await query.take(take).skip(skip).getMany(); const notes = await query.take(take).skip(skip).getMany();
found.push(...(await Notes.packMany(notes, user))); found.push(...(await Notes.packMany(notes, user)));
skip += take; skip += take;
if (notes.length < take) break; if (notes.length < take) break;
} }
} catch (error) {
throw new ApiError(meta.errors.queryError);
}
if (found.length > ps.limit) { if (found.length > ps.limit) {
found.length = ps.limit; found.length = ps.limit;

View file

@ -10,6 +10,7 @@ import { generateMutedNoteQuery } from "../../common/generate-muted-note-query.j
import { generateChannelQuery } from "../../common/generate-channel-query.js"; import { generateChannelQuery } from "../../common/generate-channel-query.js";
import { generateBlockedUserQuery } from "../../common/generate-block-query.js"; import { generateBlockedUserQuery } from "../../common/generate-block-query.js";
import { generateMutedUserRenotesQueryForNotes } from "../../common/generated-muted-renote-query.js"; import { generateMutedUserRenotesQueryForNotes } from "../../common/generated-muted-renote-query.js";
import { ApiError } from "../../error.js";
export const meta = { export const meta = {
tags: ["notes"], tags: ["notes"],
@ -27,6 +28,14 @@ export const meta = {
ref: "Note", ref: "Note",
}, },
}, },
errors: {
queryError: {
message: "Please follow more users.",
code: "QUERY_ERROR",
id: "620763f4-f621-4533-ab33-0577a1a3c343",
},
},
} as const; } as const;
export const paramDef = { export const paramDef = {
@ -154,12 +163,16 @@ export default define(meta, paramDef, async (ps, user) => {
const found = []; const found = [];
const take = Math.floor(ps.limit * 1.5); const take = Math.floor(ps.limit * 1.5);
let skip = 0; let skip = 0;
try {
while (found.length < ps.limit) { while (found.length < ps.limit) {
const notes = await query.take(take).skip(skip).getMany(); const notes = await query.take(take).skip(skip).getMany();
found.push(...(await Notes.packMany(notes, user))); found.push(...(await Notes.packMany(notes, user)));
skip += take; skip += take;
if (notes.length < take) break; if (notes.length < take) break;
} }
} catch (error) {
throw new ApiError(meta.errors.queryError);
}
if (found.length > ps.limit) { if (found.length > ps.limit) {
found.length = ps.limit; found.length = ps.limit;

View file

@ -29,6 +29,11 @@ export const meta = {
code: "NO_SUCH_LIST", code: "NO_SUCH_LIST",
id: "8fb1fbd5-e476-4c37-9fb0-43d55b63a2ff", id: "8fb1fbd5-e476-4c37-9fb0-43d55b63a2ff",
}, },
queryError: {
message: "Please follow more users.",
code: "QUERY_ERROR",
id: "620763f4-f621-4533-ab33-0577a1a3c343",
},
}, },
} as const; } as const;
@ -149,12 +154,16 @@ export default define(meta, paramDef, async (ps, user) => {
const found = []; const found = [];
const take = Math.floor(ps.limit * 1.5); const take = Math.floor(ps.limit * 1.5);
let skip = 0; let skip = 0;
try {
while (found.length < ps.limit) { while (found.length < ps.limit) {
const notes = await query.take(take).skip(skip).getMany(); const notes = await query.take(take).skip(skip).getMany();
found.push(...(await Notes.packMany(notes, user))); found.push(...(await Notes.packMany(notes, user)));
skip += take; skip += take;
if (notes.length < take) break; if (notes.length < take) break;
} }
} catch (error) {
throw new ApiError(meta.errors.queryError);
}
if (found.length > ps.limit) { if (found.length > ps.limit) {
found.length = ps.limit; found.length = ps.limit;