fix: break if no user ids left

This commit is contained in:
Namekuji 2023-08-26 12:20:43 -04:00
parent 5493fefe0f
commit 5cb04189ac
No known key found for this signature in database
GPG key ID: 1D62332C07FBA532
2 changed files with 20 additions and 5 deletions

View file

@ -406,7 +406,9 @@ export async function execPaginationQuery(
} else if (kind === "notification" && userId) { } else if (kind === "notification" && userId) {
params.push(userId, untilDate, untilDate); params.push(userId, untilDate, untilDate);
} else if (kind === "list" && ps.userIds) { } else if (kind === "list" && ps.userIds) {
params.push(ps.userIds.pop() as string, untilDate); const targetId = ps.userIds.pop();
if (!targetId) break;
params.push(targetId, untilDate);
} else { } else {
params.push(untilDate, untilDate); params.push(untilDate, untilDate);
} }
@ -415,7 +417,8 @@ export async function execPaginationQuery(
params.push(sinceDate); params.push(sinceDate);
} }
params.push(kind === "list" ? ps.limit : queryLimit); const fetchLimit = kind === "list" ? ps.limit : queryLimit;
params.push(fetchLimit);
const result = await scyllaClient.execute(query, params, { const result = await scyllaClient.execute(query, params, {
prepare: true, prepare: true,
@ -437,7 +440,7 @@ export async function execPaginationQuery(
} }
} }
if (result.rowLength < queryLimit) { if (result.rowLength < fetchLimit) {
// Reached the end of partition. Queries posts created one day before. // Reached the end of partition. Queries posts created one day before.
scannedPartitions++; scannedPartitions++;
const yesterday = new Date(untilDate.getTime() - 86400000); const yesterday = new Date(untilDate.getTime() - 86400000);

View file

@ -76,6 +76,16 @@ export default define(meta, paramDef, async (ps, user) => {
} }
if (scyllaClient) { if (scyllaClient) {
const userIds = await UserListJoinings.find({
select: ["userId"],
where: {
userListId: list.id,
},
}).then((lists) => lists.map(({ userId }) => userId));
if (userIds.length === 0) {
return await Notes.packMany([]);
}
const followingUserIds = await LocalFollowingsCache.init(user.id).then( const followingUserIds = await LocalFollowingsCache.init(user.id).then(
(cache) => cache.getAll(), (cache) => cache.getAll(),
); );
@ -106,11 +116,13 @@ export default define(meta, paramDef, async (ps, user) => {
const foundNotes = ( const foundNotes = (
(await execPaginationQuery( (await execPaginationQuery(
"list", "list",
ps, { ...ps, userIds },
{ note: filter }, { note: filter },
user.id, user.id,
)) as ScyllaNote[] )) as ScyllaNote[]
).slice(0, ps.limit * 1.5); // Some may filtered out by Notes.packMany, thus we take more than ps.limit. )
.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime())
.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))); foundPacked.push(...(await Notes.packMany(foundNotes, user)));
if (foundNotes.length < ps.limit) break; if (foundNotes.length < ps.limit) break;
ps.untilDate = foundNotes[foundNotes.length - 1].createdAt.getTime(); ps.untilDate = foundNotes[foundNotes.length - 1].createdAt.getTime();