mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 20:44:34 +00:00
improve performance of /v1/accounts/relationships
This commit is contained in:
parent
f5be341acc
commit
de26ffd60b
3 changed files with 14 additions and 12 deletions
|
@ -154,14 +154,11 @@ export class ApiAccountMastodon {
|
|||
reply.send(response);
|
||||
});
|
||||
|
||||
fastify.get<ApiAccountMastodonRoute & { Querystring: { id?: string | string[], 'id[]'?: string | string[] }}>('/v1/accounts/relationships', async (_request, reply) => {
|
||||
let ids = _request.query['id[]'] ?? _request.query['id'] ?? [];
|
||||
if (typeof ids === 'string') {
|
||||
ids = [ids];
|
||||
}
|
||||
fastify.get<ApiAccountMastodonRoute & { Querystring: { id?: string | string[] }}>('/v1/accounts/relationships', async (_request, reply) => {
|
||||
if (!_request.query.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required property "id"' });
|
||||
|
||||
const client = this.clientService.getClient(_request);
|
||||
const data = await client.getRelationships(ids);
|
||||
const data = await client.getRelationships(_request.query.id);
|
||||
const response = data.data.map(relationship => convertRelationship(relationship));
|
||||
|
||||
reply.send(response);
|
||||
|
|
|
@ -342,7 +342,7 @@ export interface MegalodonInterface {
|
|||
* @param ids Array of account IDs.
|
||||
* @return Array of Relationship.
|
||||
*/
|
||||
getRelationships(ids: Array<string>): Promise<Response<Array<Entity.Relationship>>>
|
||||
getRelationships(ids: string | Array<string>): Promise<Response<Array<Entity.Relationship>>>
|
||||
/**
|
||||
* Search for matching accounts by username or display name.
|
||||
*
|
||||
|
|
|
@ -606,11 +606,16 @@ export default class Misskey implements MegalodonInterface {
|
|||
*
|
||||
* @param ids Array of account ID, for example `['1sdfag', 'ds12aa']`.
|
||||
*/
|
||||
public async getRelationships(ids: Array<string>): Promise<Response<Array<Entity.Relationship>>> {
|
||||
return Promise.all(ids.map(id => this.getRelationship(id))).then(results => ({
|
||||
...results[0],
|
||||
data: results.map(r => r.data)
|
||||
}))
|
||||
public async getRelationships(ids: string | Array<string>): Promise<Response<Array<Entity.Relationship>>> {
|
||||
return this.client
|
||||
.post<MisskeyAPI.Entity.Relation[]>('/api/users/relation', {
|
||||
userId: ids
|
||||
})
|
||||
.then(res => {
|
||||
return Object.assign(res, {
|
||||
data: res.data.map(r => MisskeyAPI.Converter.relation(r))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue