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 label endpoints #2043

Merged
merged 14 commits into from
Feb 28, 2024
Merged

Ozone label endpoints #2043

merged 14 commits into from
Feb 28, 2024

Conversation

dholms
Copy link
Collaborator

@dholms dholms commented Jan 12, 2024

Adds endpoints for

  • subscribeLabels
  • queryLabels

Subscribe labels uses the sequencer/outbox model that we also used on the PDS, backed by Postgres & just routine polling.

Note on deploying this:
I added a new serial id column to the label table. Not exactly sure how we want to manage this one but we'll have to figure out something sneaky on it 🤔

@dholms dholms changed the title Ozone label stream Ozone label endpoints Jan 13, 2024
@dholms dholms marked this pull request as ready for review January 13, 2024 00:38
@@ -13,6 +13,9 @@ export const readEnv = (): OzoneEnvironment => {
pdsDid: envStr('OZONE_PDS_DID'),
dbPostgresUrl: envStr('OZONE_DB_POSTGRES_URL'),
dbPostgresSchema: envStr('OZONE_DB_POSTGRES_SCHEMA'),
dbPoolSize: envInt('OZONE_DB_POOL_SIZE'),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

these crept in cause I thought i was running into some connection pool issues in the test, but it turns out that wasn't the case

kept them around since it's just nice to have 👍

throw new InvalidRequestError(`invalid pattern: ${pattern}`)
}
const searchPattern = pattern.slice(0, -1)
qb = qb.orWhere('uri', 'like', `${searchPattern}%`)
Copy link
Collaborator

@devinivy devinivy Feb 28, 2024

Choose a reason for hiding this comment

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

May be nice to sanitize these search patterns so that they can't use weird arbitrary like pattern syntax.

Also just a note—I am pretty sure postgres can turn uri like '{prefix}%' into a simple range scan if uri is indexed 👍

Comment on lines +6 to +7
export default function (server: Server, ctx: AppContext) {
server.com.atproto.label.subscribeLabels(async function* ({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Tidy ✅

Comment on lines 866 to +867
oc.columns(['src', 'uri', 'cid', 'val']).doUpdateSet({
id: sql`${excluded('id')}`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting! Slightly surprised this just works, cool.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah i was unsure if it was going to. But seems to work nicely & thinking it through, it make sense since the ID is taken from the sequence before the write actually occurs

@@ -858,12 +857,14 @@ export class ModerationService {
neg: !!l.neg,
}))
const { ref } = this.db.db.dynamic
await sql`notify ${ref(LabelChannel)}`.execute(this.db.db) // emitted transactionally
Copy link
Collaborator

@devinivy devinivy Feb 28, 2024

Choose a reason for hiding this comment

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

Re: the comment—does this need to be emitted transactionally? It seems like it probably doesn't need to be transactional, and I have a feeling this method often runs outside of a transaction.

Copy link
Collaborator

@devinivy devinivy left a comment

Choose a reason for hiding this comment

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

Looks solid—nice to be able to pinch the sequencer!

Comment on lines +31 to +33
if (sources && sources.length > 0) {
builder = builder.where('src', 'in', sources)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to support both multiple sources and multiple patterns w/ pagination? I think multiple patterns w/ pagination or multiple sources w/ pagination will probably be simple enough for postgres, but all three at once could put it in a tricky spot for a large result set.

@devinivy devinivy merged commit b3434d4 into main Feb 28, 2024
10 checks passed
@devinivy devinivy deleted the label-stream branch February 28, 2024 23:26
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