From a1298b42ec3830911569b3b515353c618116771b Mon Sep 17 00:00:00 2001 From: dholms Date: Wed, 11 Oct 2023 20:12:02 -0500 Subject: [PATCH] tidy --- .../src/api/com/atproto/admin/searchRepos.ts | 16 +++++++++++++++- packages/bsky/src/api/com/atproto/admin/util.ts | 16 ++++++++++++++++ .../bsky/tests/auto-moderator/takedowns.test.ts | 4 ++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/packages/bsky/src/api/com/atproto/admin/searchRepos.ts b/packages/bsky/src/api/com/atproto/admin/searchRepos.ts index e279b2e91be..37be6791d32 100644 --- a/packages/bsky/src/api/com/atproto/admin/searchRepos.ts +++ b/packages/bsky/src/api/com/atproto/admin/searchRepos.ts @@ -1,5 +1,6 @@ import { Server } from '../../../../lexicon' import AppContext from '../../../../context' +import { addAccountInfoToRepoView, getPdsAccountInfos } from './util' export default function (server: Server, ctx: AppContext) { server.com.atproto.admin.searchRepos({ @@ -14,11 +15,24 @@ export default function (server: Server, ctx: AppContext) { const { results, cursor: resCursor } = await ctx.services .actor(db) .getSearchResults({ query, limit, cursor, includeSoftDeleted: true }) + + const [partialRepos, actorInfos] = await Promise.all([ + moderationService.views.repo(results), + getPdsAccountInfos( + ctx, + results.map((r) => r.did), + ), + ]) + + const repos = partialRepos.map((repo) => + addAccountInfoToRepoView(repo, actorInfos[repo.did] ?? null), + ) + return { encoding: 'application/json', body: { cursor: resCursor, - repos: await moderationService.views.repo(results), + repos, }, } }, diff --git a/packages/bsky/src/api/com/atproto/admin/util.ts b/packages/bsky/src/api/com/atproto/admin/util.ts index 557b33204df..eb2f73d2f93 100644 --- a/packages/bsky/src/api/com/atproto/admin/util.ts +++ b/packages/bsky/src/api/com/atproto/admin/util.ts @@ -18,6 +18,22 @@ export const getPdsAccountInfo = async ( } } +export const getPdsAccountInfos = async ( + ctx: AppContext, + dids: string[], +): Promise> => { + const unique = [...new Set(dids)] + const infos = await Promise.all( + unique.map((did) => getPdsAccountInfo(ctx, did)), + ) + return infos.reduce((acc, cur) => { + if (cur) { + acc[cur.did] = cur + } + return acc + }, {} as Record) +} + export const addAccountInfoToRepoViewDetail = ( repoView: RepoViewDetail, accountInfo: UserAccountView | null, diff --git a/packages/bsky/tests/auto-moderator/takedowns.test.ts b/packages/bsky/tests/auto-moderator/takedowns.test.ts index 6c7b0669b77..733c7a87baf 100644 --- a/packages/bsky/tests/auto-moderator/takedowns.test.ts +++ b/packages/bsky/tests/auto-moderator/takedowns.test.ts @@ -98,7 +98,7 @@ describe('takedowner', () => { .where('uri', '=', post.ref.uriStr) .select('takedownId') .executeTakeFirst() - expect(recordPds?.takedownId).toEqual(modAction.id) + expect(recordPds?.takedownId).toEqual(modAction.id.toString()) expect(testInvalidator.invalidated.length).toBe(1) expect(testInvalidator.invalidated[0].subject).toBe( @@ -140,7 +140,7 @@ describe('takedowner', () => { .where('uri', '=', res.data.uri) .select('takedownId') .executeTakeFirst() - expect(recordPds?.takedownId).toEqual(modAction.id) + expect(recordPds?.takedownId).toEqual(modAction.id.toString()) expect(testInvalidator.invalidated.length).toBe(2) expect(testInvalidator.invalidated[1].subject).toBe(