mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Merge branch 'search-pagination' into 'main'
Try using offset pagination for account search See merge request soapbox-pub/ditto!655
This commit is contained in:
commit
00146dc192
2 changed files with 9 additions and 5 deletions
|
|
@ -12,7 +12,7 @@ import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts';
|
|||
import { renderStatus } from '@/views/mastodon/statuses.ts';
|
||||
import { getFollowedPubkeys } from '@/queries.ts';
|
||||
import { getPubkeysBySearch } from '@/utils/search.ts';
|
||||
import { paginated } from '@/utils/api.ts';
|
||||
import { paginated, paginatedList } from '@/utils/api.ts';
|
||||
|
||||
const searchQuerySchema = z.object({
|
||||
q: z.string().transform(decodeURIComponent),
|
||||
|
|
@ -77,7 +77,11 @@ const searchController: AppController = async (c) => {
|
|||
hashtags: [],
|
||||
};
|
||||
|
||||
return paginated(c, events, body);
|
||||
if (result.data.type === 'accounts') {
|
||||
return paginatedList(c, { ...result.data, ...params }, body);
|
||||
} else {
|
||||
return paginated(c, events, body);
|
||||
}
|
||||
};
|
||||
|
||||
/** Get events for the search params. */
|
||||
|
|
|
|||
|
|
@ -243,18 +243,18 @@ function buildListLinkHeader(url: string, params: { offset: number; limit: numbe
|
|||
function paginatedList(
|
||||
c: AppContext,
|
||||
params: { offset: number; limit: number },
|
||||
entities: unknown[],
|
||||
body: object | unknown[],
|
||||
headers: HeaderRecord = {},
|
||||
) {
|
||||
const link = buildListLinkHeader(c.req.url, params);
|
||||
const hasMore = entities.length > 0;
|
||||
const hasMore = Array.isArray(body) ? body.length > 0 : true;
|
||||
|
||||
if (link) {
|
||||
headers.link = hasMore ? link : link.split(', ').find((link) => link.endsWith('; rel="prev"'))!;
|
||||
}
|
||||
|
||||
// Filter out undefined entities.
|
||||
const results = entities.filter(Boolean);
|
||||
const results = Array.isArray(body) ? body.filter(Boolean) : body;
|
||||
return c.json(results, 200, headers);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue