-
Notifications
You must be signed in to change notification settings - Fork 554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ Ozone batch repo and record getters #2836
Conversation
…atch-repo-and-record
const [record, accountInfo] = await Promise.all([ | ||
ctx.modService(db).views.recordDetail(params, labelers), | ||
const [records, accountInfos] = await Promise.all([ | ||
ctx.modService(db).views.recordDetail([params], labelers), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we pluralize everything that is taking a list & returning a map?
ie modService(db).views.recordDetails
and getPdsAccountInfos
|
||
const results: (RecordViewDetail | RecordViewNotFound)[] = [] | ||
|
||
params.uris.forEach((uri) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a map()
might be a bit clearer here
const results = params.uris.map((uri) => ...)
|
||
const repos: (RepoViewDetail | RepoViewNotFound)[] = [] | ||
|
||
dids.forEach((did) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same thing here: a map()
might be a bit clearer
packages/ozone/src/api/util.ts
Outdated
@@ -30,17 +30,28 @@ import { ids } from '../lexicon/lexicons' | |||
|
|||
export const getPdsAccountInfo = async ( | |||
ctx: AppContext, | |||
did: string, | |||
): Promise<AccountView | null> => { | |||
did: string | string[], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm inclined to just have this always take a string[]
if it's always returning a Map
of account views. Just keeps the function a bit simpler
@@ -224,24 +224,33 @@ export class ModerationViews { | |||
} | |||
|
|||
async repoDetail( | |||
did: string, | |||
dids: string | string[], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similarly, i'm inclined to just have this always take an array
repos.forEach((repo, did) => { | ||
const labels = [ | ||
...(localLabels.get(did) || []), | ||
...externalLabels.filter((label) => label.uri === did), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if getExternalLabels
should return a Map<string, Label[]>
instead of just a big unfiltered array. That way we don't need to repeatedly scan over the array to get our list of labels for each subject
|
||
const results = new Map<string, RecordViewDetail>() | ||
|
||
records.forEach(async (record, uri) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure you lose track of the promise like this. I think you either need to use a for loop or map()
with a Promise.all
.
I'd be inclined to do the latter so you can grab the blob infos in parallel
import { forSnapshot } from './_util' | ||
import { ids } from '../src/lexicon/lexicons' | ||
|
||
describe('admin get record view', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe('admin get record view', () => { | |
describe('admin get records view', () => { |
}) | ||
}) | ||
|
||
it('gets a records by uris', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('gets a records by uris', async () => { | |
it('get multiple records by uri', async () => { |
@@ -64,6 +64,41 @@ export const getAccount = async ( | |||
return found || null | |||
} | |||
|
|||
export const getAccounts = async ( | |||
db: AccountDb, | |||
handlesAndDids: string[], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since getAccountInfos
only takes dids, you can probably simplify this by just taking an array of DIDs (no handles)
|
||
const accounts = await selectAccountQB(db, flags) | ||
.if(handles.size > 0, (qb) => | ||
qb.where('actor.handle', 'in', Array.from(handles)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure these two .where
s strung together are going to turn into a WHERE ... AND ...
Kysely has an orWhere
function, but sometimes the grouping around those can be a little bit tricky. Partially why I recommend just ditching the handles 😛
@@ -64,6 +64,41 @@ export const getAccount = async ( | |||
return found || null | |||
} | |||
|
|||
export const getAccounts = async ( | |||
db: AccountDb, | |||
handlesAndDids: string[], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also kysely gets mad if you pass in an empty array, so the first thing I'd do in this function is check if the array length is 0 & if so then just return an empty map
): Promise<Map<string, CodeDetail[]>> => { | ||
const results = new Map<string, CodeDetail[]>() | ||
const res = await selectInviteCodesQb(db) | ||
.where('forAccount', 'in', dids) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like above^^ make sure you don't pass in an empty array
@@ -155,6 +155,30 @@ export const getAccountInviteCodes = async ( | |||
})) | |||
} | |||
|
|||
export const getAccountsInviteCodes = async ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can dry this up a bit & use this function to implement getAccountInviteCodes
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decided to stick to the pattern of take an array and return a map
and got rid of the singular getAccountInviteCodes
in favor of getAccountsInviteCodes
const managesOwnInvites = !ctx.cfg.entryway | ||
const infos: AccountView[] = [] | ||
|
||
accounts.forEach((account) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.map()
might be a bit cozier here too
Overall looking pretty good! Some style tweaks and what not but nothing too major. Main thing that is prone to errors is accidentally passing empty arrays into kysely |
aab44ab
to
e5ec727
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking good ✨
This PR introduces 2 new endpoints on ozone
tools.ozone.moderation.getRecords
andtools.ozone.moderation.getRepos
in order to allow fetching repo and record details in batches.