Fix antenna pagination

This commit is contained in:
Laura Hausmann 2023-08-07 19:41:24 +02:00
parent 471d39da0b
commit aeddce2a60
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 55 additions and 22 deletions

View file

@ -25,6 +25,16 @@ export const meta = {
}, },
res: { res: {
type: "object",
optional: false,
nullable: false,
properties: {
pagination: {
type: "string",
nullable: false,
optional: false,
},
notes: {
type: "array", type: "array",
optional: false, optional: false,
nullable: false, nullable: false,
@ -34,6 +44,8 @@ export const meta = {
nullable: false, nullable: false,
ref: "Note", ref: "Note",
}, },
}
}
}, },
} as const; } as const;
@ -42,10 +54,7 @@ export const paramDef = {
properties: { properties: {
antennaId: { type: "string", format: "misskey:id" }, antennaId: { type: "string", format: "misskey:id" },
limit: { type: "integer", minimum: 1, maximum: 100, default: 10 }, limit: { type: "integer", minimum: 1, maximum: 100, default: 10 },
sinceId: { type: "string", format: "misskey:id" }, pagination: { type: "string", default: "+" },
untilId: { type: "string", format: "misskey:id" },
sinceDate: { type: "integer" },
untilDate: { type: "integer" },
}, },
required: ["antennaId"], required: ["antennaId"],
} as const; } as const;
@ -62,30 +71,25 @@ export default define(meta, paramDef, async (ps, user) => {
const noteIdsRes = await redisClient.xrevrange( const noteIdsRes = await redisClient.xrevrange(
`antennaTimeline:${antenna.id}`, `antennaTimeline:${antenna.id}`,
ps.untilDate || "+", ps.pagination || "+",
"-", "-",
"COUNT", "COUNT",
ps.limit + 1, ps.limit + 1,
); // untilIdに指定したものも含まれるため+1 );
if (noteIdsRes.length === 0) { if (noteIdsRes.length === 0) {
return []; return [];
} }
const noteIds = noteIdsRes const noteIds = noteIdsRes
.map((x) => x[1][1]) .map((x) => x[1][1]);
.filter((x) => x !== ps.untilId);
if (noteIds.length === 0) { if (noteIds.length === 0) {
return []; return {pagination: "", notes: []};
} }
const query = makePaginationQuery( const query = makePaginationQuery(
Notes.createQueryBuilder("note"), Notes.createQueryBuilder("note")
ps.sinceId,
ps.untilId,
ps.sinceDate,
ps.untilDate,
) )
.where("note.id IN (:...noteIds)", { noteIds: noteIds }) .where("note.id IN (:...noteIds)", { noteIds: noteIds })
.innerJoinAndSelect("note.user", "user") .innerJoinAndSelect("note.user", "user")
@ -111,5 +115,8 @@ export default define(meta, paramDef, async (ps, user) => {
readNote(user.id, notes); readNote(user.id, notes);
} }
return await Notes.packMany(notes, user); return {
pagination: noteIdsRes[noteIdsRes.length - 1][0],
notes: await Notes.packMany(notes, user),
};
}); });

View file

@ -139,6 +139,8 @@ const isBackTop = ref(false);
const empty = computed(() => items.value.length === 0); const empty = computed(() => items.value.length === 0);
const error = ref(false); const error = ref(false);
let redisPaginationStr = ref("+");
const init = async (): Promise<void> => { const init = async (): Promise<void> => {
queue.value = []; queue.value = [];
fetching.value = true; fetching.value = true;
@ -156,6 +158,10 @@ const init = async (): Promise<void> => {
}) })
.then( .then(
(res) => { (res) => {
if (props.pagination.endpoint == 'antennas/notes') {
redisPaginationStr = res.pagination;
res = res.notes;
}
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
const item = res[i]; const item = res[i];
if (props.pagination.reversed) { if (props.pagination.reversed) {
@ -251,6 +257,11 @@ const fetchMore = async (): Promise<void> => {
? props.pagination.params.value ? props.pagination.params.value
: props.pagination.params : props.pagination.params
: {}; : {};
if (props.pagination.endpoint == 'antennas/notes') {
params.pagination = redisPaginationStr;
}
await os await os
.api(props.pagination.endpoint, { .api(props.pagination.endpoint, {
...params, ...params,
@ -269,6 +280,11 @@ const fetchMore = async (): Promise<void> => {
}) })
.then( .then(
(res) => { (res) => {
if (props.pagination.endpoint == 'antennas/notes') {
redisPaginationStr = res.pagination;
res = res.notes;
}
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
const item = res[i]; const item = res[i];
if (props.pagination.reversed) { if (props.pagination.reversed) {
@ -312,6 +328,11 @@ const fetchMoreAhead = async (): Promise<void> => {
? props.pagination.params.value ? props.pagination.params.value
: props.pagination.params : props.pagination.params
: {}; : {};
if (props.pagination.endpoint == 'antennas/notes') {
params.pagination = redisPaginationStr;
}
await os await os
.api(props.pagination.endpoint, { .api(props.pagination.endpoint, {
...params, ...params,
@ -330,6 +351,11 @@ const fetchMoreAhead = async (): Promise<void> => {
}) })
.then( .then(
(res) => { (res) => {
if (props.pagination.endpoint == 'antennas/notes') {
redisPaginationStr = res.pagination;
res = res.notes;
}
if (res.length > SECOND_FETCH_LIMIT) { if (res.length > SECOND_FETCH_LIMIT) {
res.pop(); res.pop();
items.value = props.pagination.reversed items.value = props.pagination.reversed