mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-25 19:37:34 -07:00
[backend] Don't fetch more notes than requested
This commit is contained in:
parent
735fd37707
commit
fd6ee32832
10 changed files with 22 additions and 170 deletions
|
@ -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 {
|
try {
|
||||||
while (found.length < ps.limit) {
|
const notes = await query.take(ps.limit).getMany();
|
||||||
const notes = await query.take(take).skip(skip).getMany();
|
return await Notes.packMany(notes, user);
|
||||||
found.push(...(await Notes.packMany(notes, user)));
|
|
||||||
skip += take;
|
|
||||||
if (notes.length < take) break;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new ApiError(meta.errors.queryError);
|
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);
|
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 {
|
try {
|
||||||
while (found.length < ps.limit) {
|
const notes = await query.take(ps.limit).getMany();
|
||||||
const notes = await query.take(take).skip(skip).getMany();
|
return await Notes.packMany(notes, user);
|
||||||
found.push(...(await Notes.packMany(notes, user)));
|
|
||||||
skip += take;
|
|
||||||
if (notes.length < take) break;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new ApiError(meta.errors.queryError);
|
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 {
|
try {
|
||||||
while (found.length < ps.limit) {
|
const notes = await query.take(ps.limit).getMany();
|
||||||
const notes = await query.take(take).skip(skip).getMany();
|
return await Notes.packMany(notes, user);
|
||||||
found.push(...(await Notes.packMany(notes, user)));
|
|
||||||
skip += take;
|
|
||||||
if (notes.length < take) break;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new ApiError(meta.errors.queryError);
|
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());
|
query.setParameters(followingQuery.getParameters());
|
||||||
}
|
}
|
||||||
|
|
||||||
// We fetch more than requested because some may be filtered out, and if there's less than
|
const notes = await query.take(ps.limit).getMany();
|
||||||
// requested, the pagination stops.
|
const packed = await Notes.packMany(notes, user);
|
||||||
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) {
|
read(user.id, packed);
|
||||||
found.length = ps.limit;
|
|
||||||
}
|
|
||||||
|
|
||||||
read(user.id, found);
|
return packed;
|
||||||
|
|
||||||
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 {
|
try {
|
||||||
while (found.length < ps.limit) {
|
const notes = await query.take(ps.limit).getMany();
|
||||||
const notes = await query.take(take).skip(skip).getMany();
|
return await Notes.packMany(notes, user);
|
||||||
found.push(...(await Notes.packMany(notes, user)));
|
|
||||||
skip += take;
|
|
||||||
if (notes.length < take) break;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new ApiError(meta.errors.queryError);
|
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) generateMutedUserQuery(query, user);
|
||||||
if (user) generateBlockedUserQuery(query, user);
|
if (user) generateBlockedUserQuery(query, user);
|
||||||
|
|
||||||
// We fetch more than requested because some may be filtered out, and if there's less than
|
const notes = await query.take(ps.limit).getMany();
|
||||||
// requested, the pagination stops.
|
return await Notes.packMany(notes, user);
|
||||||
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;
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -52,21 +52,6 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
if (user) generateMutedUserQuery(query, user);
|
if (user) generateMutedUserQuery(query, user);
|
||||||
if (user) generateBlockedUserQuery(query, user);
|
if (user) generateBlockedUserQuery(query, user);
|
||||||
|
|
||||||
// We fetch more than requested because some may be filtered out, and if there's less than
|
const notes = await query.take(ps.limit).getMany();
|
||||||
// requested, the pagination stops.
|
return await Notes.packMany(notes, user);
|
||||||
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;
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -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
|
const notes = await query.take(ps.limit).getMany();
|
||||||
// requested, the pagination stops.
|
return await Notes.packMany(notes, me);
|
||||||
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;
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -143,25 +143,10 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
activeUsersChart.read(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 {
|
try {
|
||||||
while (found.length < ps.limit) {
|
const notes = await query.take(ps.limit).getMany();
|
||||||
const notes = await query.take(take).skip(skip).getMany();
|
return await Notes.packMany(notes, user);
|
||||||
found.push(...(await Notes.packMany(notes, user)));
|
|
||||||
skip += take;
|
|
||||||
if (notes.length < take) break;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new ApiError(meta.errors.queryError);
|
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 {
|
try {
|
||||||
while (found.length < ps.limit) {
|
const notes = await query.take(ps.limit).getMany();
|
||||||
const notes = await query.take(take).skip(skip).getMany();
|
return await Notes.packMany(notes, user);
|
||||||
found.push(...(await Notes.packMany(notes, user)));
|
|
||||||
skip += take;
|
|
||||||
if (notes.length < take) break;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new ApiError(meta.errors.queryError);
|
throw new ApiError(meta.errors.queryError);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found.length > ps.limit) {
|
|
||||||
found.length = ps.limit;
|
|
||||||
}
|
|
||||||
|
|
||||||
return found;
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue