mirror of
https://iceshrimp.dev/crimekillz/iceshrimp-161sh.git
synced 2024-11-21 19:53:50 +01:00
[backend] Don't fetch more notes than requested
This commit is contained in:
parent
735fd37707
commit
fd6ee32832
@ -106,25 +106,10 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
}
|
||||
});
|
||||
|
||||
// We fetch more than requested because some may be filtered out, and if there's less than
|
||||
// requested, the pagination stops.
|
||||
const found = [];
|
||||
const take = Math.floor(ps.limit * 1.5);
|
||||
let skip = 0;
|
||||
try {
|
||||
while (found.length < ps.limit) {
|
||||
const notes = await query.take(take).skip(skip).getMany();
|
||||
found.push(...(await Notes.packMany(notes, user)));
|
||||
skip += take;
|
||||
if (notes.length < take) break;
|
||||
}
|
||||
const notes = await query.take(ps.limit).getMany();
|
||||
return await Notes.packMany(notes, user);
|
||||
} catch (error) {
|
||||
throw new ApiError(meta.errors.queryError);
|
||||
}
|
||||
|
||||
if (found.length > ps.limit) {
|
||||
found.length = ps.limit;
|
||||
}
|
||||
|
||||
return found;
|
||||
});
|
||||
|
@ -165,25 +165,10 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
activeUsersChart.read(user);
|
||||
});
|
||||
|
||||
// We fetch more than requested because some may be filtered out, and if there's less than
|
||||
// requested, the pagination stops.
|
||||
const found = [];
|
||||
const take = Math.floor(ps.limit * 1.5);
|
||||
let skip = 0;
|
||||
try {
|
||||
while (found.length < ps.limit) {
|
||||
const notes = await query.take(take).skip(skip).getMany();
|
||||
found.push(...(await Notes.packMany(notes, user)));
|
||||
skip += take;
|
||||
if (notes.length < take) break;
|
||||
}
|
||||
const notes = await query.take(ps.limit).getMany();
|
||||
return await Notes.packMany(notes, user);
|
||||
} catch (error) {
|
||||
throw new ApiError(meta.errors.queryError);
|
||||
}
|
||||
|
||||
if (found.length > ps.limit) {
|
||||
found.length = ps.limit;
|
||||
}
|
||||
|
||||
return found;
|
||||
});
|
||||
|
@ -135,25 +135,10 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
}
|
||||
});
|
||||
|
||||
// We fetch more than requested because some may be filtered out, and if there's less than
|
||||
// requested, the pagination stops.
|
||||
const found = [];
|
||||
const take = Math.floor(ps.limit * 1.5);
|
||||
let skip = 0;
|
||||
try {
|
||||
while (found.length < ps.limit) {
|
||||
const notes = await query.take(take).skip(skip).getMany();
|
||||
found.push(...(await Notes.packMany(notes, user)));
|
||||
skip += take;
|
||||
if (notes.length < take) break;
|
||||
}
|
||||
const notes = await query.take(ps.limit).getMany();
|
||||
return await Notes.packMany(notes, user);
|
||||
} catch (error) {
|
||||
throw new ApiError(meta.errors.queryError);
|
||||
}
|
||||
|
||||
if (found.length > ps.limit) {
|
||||
found.length = ps.limit;
|
||||
}
|
||||
|
||||
return found;
|
||||
});
|
||||
|
@ -80,23 +80,10 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
query.setParameters(followingQuery.getParameters());
|
||||
}
|
||||
|
||||
// We fetch more than requested because some may be filtered out, and if there's less than
|
||||
// requested, the pagination stops.
|
||||
const found = [];
|
||||
const take = Math.floor(ps.limit * 1.5);
|
||||
let skip = 0;
|
||||
while (found.length < ps.limit) {
|
||||
const notes = await query.take(take).skip(skip).getMany();
|
||||
found.push(...(await Notes.packMany(notes, user)));
|
||||
skip += take;
|
||||
if (notes.length < take) break;
|
||||
}
|
||||
const notes = await query.take(ps.limit).getMany();
|
||||
const packed = await Notes.packMany(notes, user);
|
||||
|
||||
if (found.length > ps.limit) {
|
||||
found.length = ps.limit;
|
||||
}
|
||||
read(user.id, packed);
|
||||
|
||||
read(user.id, found);
|
||||
|
||||
return found;
|
||||
return packed;
|
||||
});
|
||||
|
@ -135,25 +135,10 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
}
|
||||
});
|
||||
|
||||
// We fetch more than requested because some may be filtered out, and if there's less than
|
||||
// requested, the pagination stops.
|
||||
const found = [];
|
||||
const take = Math.floor(ps.limit * 1.5);
|
||||
let skip = 0;
|
||||
try {
|
||||
while (found.length < ps.limit) {
|
||||
const notes = await query.take(take).skip(skip).getMany();
|
||||
found.push(...(await Notes.packMany(notes, user)));
|
||||
skip += take;
|
||||
if (notes.length < take) break;
|
||||
}
|
||||
const notes = await query.take(ps.limit).getMany();
|
||||
return await Notes.packMany(notes, user);
|
||||
} catch (error) {
|
||||
throw new ApiError(meta.errors.queryError);
|
||||
}
|
||||
|
||||
if (found.length > ps.limit) {
|
||||
found.length = ps.limit;
|
||||
}
|
||||
|
||||
return found;
|
||||
});
|
||||
|
@ -75,21 +75,6 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
if (user) generateMutedUserQuery(query, user);
|
||||
if (user) generateBlockedUserQuery(query, user);
|
||||
|
||||
// We fetch more than requested because some may be filtered out, and if there's less than
|
||||
// requested, the pagination stops.
|
||||
const found = [];
|
||||
const take = Math.floor(ps.limit * 1.5);
|
||||
let skip = 0;
|
||||
while (found.length < ps.limit) {
|
||||
const notes = await query.take(take).skip(skip).getMany();
|
||||
found.push(...(await Notes.packMany(notes, user)));
|
||||
skip += take;
|
||||
if (notes.length < take) break;
|
||||
}
|
||||
|
||||
if (found.length > ps.limit) {
|
||||
found.length = ps.limit;
|
||||
}
|
||||
|
||||
return found;
|
||||
const notes = await query.take(ps.limit).getMany();
|
||||
return await Notes.packMany(notes, user);
|
||||
});
|
||||
|
@ -52,21 +52,6 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
if (user) generateMutedUserQuery(query, user);
|
||||
if (user) generateBlockedUserQuery(query, user);
|
||||
|
||||
// We fetch more than requested because some may be filtered out, and if there's less than
|
||||
// requested, the pagination stops.
|
||||
const found = [];
|
||||
const take = Math.floor(ps.limit * 1.5);
|
||||
let skip = 0;
|
||||
while (found.length < ps.limit) {
|
||||
const notes = await query.take(take).skip(skip).getMany();
|
||||
found.push(...(await Notes.packMany(notes, user)));
|
||||
skip += take;
|
||||
if (notes.length < take) break;
|
||||
}
|
||||
|
||||
if (found.length > ps.limit) {
|
||||
found.length = ps.limit;
|
||||
}
|
||||
|
||||
return found;
|
||||
const notes = await query.take(ps.limit).getMany();
|
||||
return await Notes.packMany(notes, user);
|
||||
});
|
||||
|
@ -139,21 +139,6 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||
}
|
||||
}
|
||||
|
||||
// We fetch more than requested because some may be filtered out, and if there's less than
|
||||
// requested, the pagination stops.
|
||||
const found = [];
|
||||
const take = Math.floor(ps.limit * 1.5);
|
||||
let skip = 0;
|
||||
while (found.length < ps.limit) {
|
||||
const notes = await query.take(take).skip(skip).getMany();
|
||||
found.push(...(await Notes.packMany(notes, me)));
|
||||
skip += take;
|
||||
if (notes.length < take) break;
|
||||
}
|
||||
|
||||
if (found.length > ps.limit) {
|
||||
found.length = ps.limit;
|
||||
}
|
||||
|
||||
return found;
|
||||
const notes = await query.take(ps.limit).getMany();
|
||||
return await Notes.packMany(notes, me);
|
||||
});
|
||||
|
@ -143,25 +143,10 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
activeUsersChart.read(user);
|
||||
});
|
||||
|
||||
// We fetch more than requested because some may be filtered out, and if there's less than
|
||||
// requested, the pagination stops.
|
||||
const found = [];
|
||||
const take = Math.floor(ps.limit * 1.5);
|
||||
let skip = 0;
|
||||
try {
|
||||
while (found.length < ps.limit) {
|
||||
const notes = await query.take(take).skip(skip).getMany();
|
||||
found.push(...(await Notes.packMany(notes, user)));
|
||||
skip += take;
|
||||
if (notes.length < take) break;
|
||||
}
|
||||
const notes = await query.take(ps.limit).getMany();
|
||||
return await Notes.packMany(notes, user);
|
||||
} catch (error) {
|
||||
throw new ApiError(meta.errors.queryError);
|
||||
}
|
||||
|
||||
if (found.length > ps.limit) {
|
||||
found.length = ps.limit;
|
||||
}
|
||||
|
||||
return found;
|
||||
});
|
||||
|
@ -143,25 +143,10 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
}
|
||||
});
|
||||
|
||||
// We fetch more than requested because some may be filtered out, and if there's less than
|
||||
// requested, the pagination stops.
|
||||
const found = [];
|
||||
const take = Math.floor(ps.limit * 1.5);
|
||||
let skip = 0;
|
||||
try {
|
||||
while (found.length < ps.limit) {
|
||||
const notes = await query.take(take).skip(skip).getMany();
|
||||
found.push(...(await Notes.packMany(notes, user)));
|
||||
skip += take;
|
||||
if (notes.length < take) break;
|
||||
}
|
||||
const notes = await query.take(ps.limit).getMany();
|
||||
return await Notes.packMany(notes, user);
|
||||
} catch (error) {
|
||||
throw new ApiError(meta.errors.queryError);
|
||||
}
|
||||
|
||||
if (found.length > ps.limit) {
|
||||
found.length = ps.limit;
|
||||
}
|
||||
|
||||
return found;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user