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("LIMIT 100");
const query = queryParts.join(" ");
return {

View file

@ -138,10 +138,20 @@ export default define(meta, paramDef, async (ps, user) => {
return filtered;
};
const foundNotes = await execNotePaginationQuery(ps, filter);
return await Notes.packMany(foundNotes.slice(0, ps.limit), user, {
scyllaNote: true,
});
const foundPacked = [];
while (foundPacked.length < ps.limit) {
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

View file

@ -165,10 +165,20 @@ export default define(meta, paramDef, async (ps, user) => {
return filtered;
};
const foundNotes = await execNotePaginationQuery(ps, filter);
return await Notes.packMany(foundNotes.slice(0, ps.limit), user, {
scyllaNote: true,
});
const foundPacked = [];
while (foundPacked.length < ps.limit) {
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

View file

@ -180,10 +180,20 @@ export default define(meta, paramDef, async (ps, user) => {
return filtered;
};
const foundNotes = await execNotePaginationQuery(ps, filter);
return await Notes.packMany(foundNotes.slice(0, ps.limit), user, {
scyllaNote: true,
});
const foundPacked = [];
while (foundPacked.length < ps.limit) {
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

View file

@ -102,10 +102,21 @@ export default define(meta, paramDef, async (ps, user) => {
return filtered;
};
const foundNotes = await execNotePaginationQuery(ps, filter, 1);
return await Notes.packMany(foundNotes.slice(0, ps.limit), user, {
scyllaNote: true,
});
const foundPacked = [];
let untilDate: number | undefined;
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(

View file

@ -152,10 +152,20 @@ export default define(meta, paramDef, async (ps, user) => {
return filtered;
};
const foundNotes = await execNotePaginationQuery(ps, filter);
return await Notes.packMany(foundNotes.slice(0, ps.limit), user, {
scyllaNote: true,
});
const foundPacked = [];
while (foundPacked.length < ps.limit) {
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();