mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Separate listPagination
This commit is contained in:
parent
d285b7dced
commit
5d6ab9f63b
5 changed files with 17 additions and 8 deletions
|
|
@ -4,9 +4,7 @@ import { serveStatic } from '@hono/hono/deno';
|
||||||
import { logger } from '@hono/hono/logger';
|
import { logger } from '@hono/hono/logger';
|
||||||
import { NostrEvent, NostrSigner, NStore, NUploader } from '@nostrify/nostrify';
|
import { NostrEvent, NostrSigner, NStore, NUploader } from '@nostrify/nostrify';
|
||||||
import Debug from '@soapbox/stickynotes/debug';
|
import Debug from '@soapbox/stickynotes/debug';
|
||||||
import { SetRequired } from 'type-fest';
|
|
||||||
|
|
||||||
import { DittoPagination } from '@/interfaces/DittoPagination.ts';
|
|
||||||
import { Time } from '@/utils/time.ts';
|
import { Time } from '@/utils/time.ts';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
|
@ -137,7 +135,9 @@ interface AppEnv extends HonoEnv {
|
||||||
/** Storage for the user, might filter out unwanted content. */
|
/** Storage for the user, might filter out unwanted content. */
|
||||||
store: NStore;
|
store: NStore;
|
||||||
/** Normalized pagination params. */
|
/** Normalized pagination params. */
|
||||||
pagination: SetRequired<DittoPagination, 'limit' | 'offset'>;
|
pagination: { since?: number; until?: number; limit: number };
|
||||||
|
/** Normalized list pagination params. */
|
||||||
|
listPagination: { offset: number; limit: number };
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -563,7 +563,7 @@ const zapController: AppController = async (c) => {
|
||||||
|
|
||||||
const zappedByController: AppController = async (c) => {
|
const zappedByController: AppController = async (c) => {
|
||||||
const id = c.req.param('id');
|
const id = c.req.param('id');
|
||||||
const params = c.get('pagination');
|
const params = c.get('listPagination');
|
||||||
const store = await Storages.db();
|
const store = await Storages.db();
|
||||||
const db = await DittoDB.getInstance();
|
const db = await DittoDB.getInstance();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts';
|
||||||
|
|
||||||
export const suggestionsV1Controller: AppController = async (c) => {
|
export const suggestionsV1Controller: AppController = async (c) => {
|
||||||
const signal = c.req.raw.signal;
|
const signal = c.req.raw.signal;
|
||||||
const params = c.get('pagination');
|
const params = c.get('listPagination');
|
||||||
const suggestions = await renderV2Suggestions(c, params, signal);
|
const suggestions = await renderV2Suggestions(c, params, signal);
|
||||||
const accounts = suggestions.map(({ account }) => account);
|
const accounts = suggestions.map(({ account }) => account);
|
||||||
return paginatedList(c, params, accounts);
|
return paginatedList(c, params, accounts);
|
||||||
|
|
@ -18,7 +18,7 @@ export const suggestionsV1Controller: AppController = async (c) => {
|
||||||
|
|
||||||
export const suggestionsV2Controller: AppController = async (c) => {
|
export const suggestionsV2Controller: AppController = async (c) => {
|
||||||
const signal = c.req.raw.signal;
|
const signal = c.req.raw.signal;
|
||||||
const params = c.get('pagination');
|
const params = c.get('listPagination');
|
||||||
const suggestions = await renderV2Suggestions(c, params, signal);
|
const suggestions = await renderV2Suggestions(c, params, signal);
|
||||||
return paginatedList(c, params, suggestions);
|
return paginatedList(c, params, suggestions);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,16 @@ export const paginationMiddleware: AppMiddleware = async (c, next) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.set('pagination', pagination);
|
c.set('pagination', {
|
||||||
|
since: pagination.since,
|
||||||
|
until: pagination.until,
|
||||||
|
limit: pagination.limit,
|
||||||
|
});
|
||||||
|
|
||||||
|
c.set('listPagination', {
|
||||||
|
limit: pagination.limit,
|
||||||
|
offset: pagination.offset,
|
||||||
|
});
|
||||||
|
|
||||||
await next();
|
await next();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ async function renderEventAccounts(c: AppContext, filters: NostrFilter[], opts?:
|
||||||
}
|
}
|
||||||
|
|
||||||
async function renderAccounts(c: AppContext, pubkeys: string[]) {
|
async function renderAccounts(c: AppContext, pubkeys: string[]) {
|
||||||
const { offset, limit } = c.get('pagination');
|
const { offset, limit } = c.get('listPagination');
|
||||||
const authors = pubkeys.reverse().slice(offset, offset + limit);
|
const authors = pubkeys.reverse().slice(offset, offset + limit);
|
||||||
|
|
||||||
const store = await Storages.db();
|
const store = await Storages.db();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue