fix: take more than requested

This commit is contained in:
Namekuji 2023-08-10 02:40:02 -04:00
parent 5828fa7a14
commit 618dc8349c
No known key found for this signature in database
GPG key ID: 1D62332C07FBA532
6 changed files with 73 additions and 20 deletions

View file

@ -280,6 +280,8 @@ export function prepareNoteQuery(ps: {
queryParts.push(`AND "createdAt" > ?`); queryParts.push(`AND "createdAt" > ?`);
} }
queryParts.push("LIMIT 100");
const query = queryParts.join(" "); const query = queryParts.join(" ");
return { return {

View file

@ -138,10 +138,20 @@ export default define(meta, paramDef, async (ps, user) => {
return filtered; return filtered;
}; };
const foundNotes = await execNotePaginationQuery(ps, filter); const foundPacked = [];
return await Notes.packMany(foundNotes.slice(0, ps.limit), user, { while (foundPacked.length < ps.limit) {
scyllaNote: true, const foundNotes = (await execNotePaginationQuery(ps, filter)).slice(
}); 0,
ps.limit * 1.5,
); // Some may filtered out by Notes.packMany, thus we take more than ps.limit.
foundPacked.push(
...(await Notes.packMany(foundNotes, user, { scyllaNote: true })),
);
if (foundNotes.length < ps.limit) break;
ps.untilDate = foundNotes[foundNotes.length - 1].createdAt.getTime();
}
return foundPacked.slice(0, ps.limit);
} }
//#region Construct query //#region Construct query

View file

@ -165,10 +165,20 @@ export default define(meta, paramDef, async (ps, user) => {
return filtered; return filtered;
}; };
const foundNotes = await execNotePaginationQuery(ps, filter); const foundPacked = [];
return await Notes.packMany(foundNotes.slice(0, ps.limit), user, { while (foundPacked.length < ps.limit) {
scyllaNote: true, const foundNotes = (await execNotePaginationQuery(ps, filter)).slice(
}); 0,
ps.limit * 1.5,
); // Some may filtered out by Notes.packMany, thus we take more than ps.limit.
foundPacked.push(
...(await Notes.packMany(foundNotes, user, { scyllaNote: true })),
);
if (foundNotes.length < ps.limit) break;
ps.untilDate = foundNotes[foundNotes.length - 1].createdAt.getTime();
}
return foundPacked.slice(0, ps.limit);
} }
//#region Construct query //#region Construct query

View file

@ -180,10 +180,20 @@ export default define(meta, paramDef, async (ps, user) => {
return filtered; return filtered;
}; };
const foundNotes = await execNotePaginationQuery(ps, filter); const foundPacked = [];
return await Notes.packMany(foundNotes.slice(0, ps.limit), user, { while (foundPacked.length < ps.limit) {
scyllaNote: true, const foundNotes = (await execNotePaginationQuery(ps, filter)).slice(
}); 0,
ps.limit * 1.5,
); // Some may filtered out by Notes.packMany, thus we take more than ps.limit.
foundPacked.push(
...(await Notes.packMany(foundNotes, user, { scyllaNote: true })),
);
if (foundNotes.length < ps.limit) break;
ps.untilDate = foundNotes[foundNotes.length - 1].createdAt.getTime();
}
return foundPacked.slice(0, ps.limit);
} }
//#region Construct query //#region Construct query

View file

@ -102,10 +102,21 @@ export default define(meta, paramDef, async (ps, user) => {
return filtered; return filtered;
}; };
const foundNotes = await execNotePaginationQuery(ps, filter, 1); const foundPacked = [];
return await Notes.packMany(foundNotes.slice(0, ps.limit), user, { let untilDate: number | undefined;
scyllaNote: true, while (foundPacked.length < ps.limit) {
}); const foundNotes = (await execNotePaginationQuery({...ps, untilDate}, filter)).slice(
0,
ps.limit * 1.5,
); // Some may filtered out by Notes.packMany, thus we take more than ps.limit.
foundPacked.push(
...(await Notes.packMany(foundNotes, user, { scyllaNote: true })),
);
if (foundNotes.length < ps.limit) break;
untilDate = foundNotes[foundNotes.length - 1].createdAt.getTime();
}
return foundPacked.slice(0, ps.limit);
} }
const query = makePaginationQuery( const query = makePaginationQuery(

View file

@ -152,10 +152,20 @@ export default define(meta, paramDef, async (ps, user) => {
return filtered; return filtered;
}; };
const foundNotes = await execNotePaginationQuery(ps, filter); const foundPacked = [];
return await Notes.packMany(foundNotes.slice(0, ps.limit), user, { while (foundPacked.length < ps.limit) {
scyllaNote: true, const foundNotes = (await execNotePaginationQuery(ps, filter)).slice(
}); 0,
ps.limit * 1.5,
); // Some may filtered out by Notes.packMany, thus we take more than ps.limit.
foundPacked.push(
...(await Notes.packMany(foundNotes, user, { scyllaNote: true })),
);
if (foundNotes.length < ps.limit) break;
ps.untilDate = foundNotes[foundNotes.length - 1].createdAt.getTime();
}
return foundPacked.slice(0, ps.limit);
} }
const hasFollowing = await followingsCache.exists(); const hasFollowing = await followingsCache.exists();