Skip to content
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

Merged
merged 14 commits into from
Oct 1, 2024
Merged

Conversation

foysalit
Copy link
Contributor

This PR introduces 2 new endpoints on ozone tools.ozone.moderation.getRecords and tools.ozone.moderation.getRepos in order to allow fetching repo and record details in batches.

@foysalit foysalit marked this pull request as ready for review September 30, 2024 07:55
@foysalit foysalit changed the title Ozone batch repo and record getters ✨ Ozone batch repo and record getters Sep 30, 2024
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),
Copy link
Collaborator

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) => {
Copy link
Collaborator

@dholms dholms Sep 30, 2024

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) => {
Copy link
Collaborator

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

@@ -30,17 +30,28 @@ import { ids } from '../lexicon/lexicons'

export const getPdsAccountInfo = async (
ctx: AppContext,
did: string,
): Promise<AccountView | null> => {
did: string | string[],
Copy link
Collaborator

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[],
Copy link
Collaborator

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),
Copy link
Collaborator

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) => {
Copy link
Collaborator

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', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
describe('admin get record view', () => {
describe('admin get records view', () => {

})
})

it('gets a records by uris', async () => {
Copy link
Collaborator

@dholms dholms Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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[],
Copy link
Collaborator

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)),
Copy link
Collaborator

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 .wheres 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[],
Copy link
Collaborator

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)
Copy link
Collaborator

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 (
Copy link
Collaborator

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?

Copy link
Contributor Author

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) => {
Copy link
Collaborator

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

@dholms
Copy link
Collaborator

dholms commented Oct 1, 2024

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 where() clauses

@foysalit foysalit force-pushed the ozone-batch-repo-and-record branch from aab44ab to e5ec727 Compare October 1, 2024 09:13
@foysalit foysalit requested a review from dholms October 1, 2024 12:15
Copy link
Collaborator

@dholms dholms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good ✨

@foysalit foysalit merged commit a2bad97 into main Oct 1, 2024
10 checks passed
@foysalit foysalit deleted the ozone-batch-repo-and-record branch October 1, 2024 17:37
@github-actions github-actions bot mentioned this pull request Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants