-
-
Notifications
You must be signed in to change notification settings - Fork 348
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
[feature] Conversations API #3013
[feature] Conversations API #3013
Conversation
548b244
to
bf42ce8
Compare
87f5497
to
31b260d
Compare
There are some experimental bits in this one:
|
// in each conversation for which the deleted status is the last status | ||
// (if there are such statuses). | ||
conversationStatusesTempTable := bun.Ident("conversation_statuses_" + id.NewULID()) | ||
if _, err := tx.NewRaw( |
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 really not very keen on these raw transactions tbh. Is there no way with bun to do this jiggery pokery? If there is, I'd much rather we use that, since it gives us all the dialect-specific escaping, sanitization, etc.
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 do. This iteration ended up not using anything that we definitely can't do in Bun.
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.
Not quite true, turns out Bun's NewCreateTable
can't do CREATE TABLE … AS SELECT …
because it assumes that there's always a parenthesized column list, so we still have to use raw queries to create these tables, or do even more work to rewrite them as the more portable CREATE TABLE
followed by INSERT … SELECT
. But we can use a very short raw query parameterized with a Bun subquery for the SELECT
part, and I think that's a decent tradeoff.
I also think we're not getting anything in terms of escaping or type checking by using Bun's query builders that pure raw queries can't also do: raw queries can still use placeholders and escaping, and Bun's query builders can't tell me if I spelled a column name wrong at compile time, so the only benefit is that a subset of SQL keywords get checked at compile time, and the cost is that it's a lot less readable, IMO, especially with our frequently-unnecessary house style use of bun.Ident
.
Take a look, and let me know if I'm missing any tricks.
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.
If we end up using this pattern again, we can add a small CreateTableAsQuery
/NewCreateTableAs
helper along the lines of UpsertQuery
/NewUpsert
, but it doesn't seem worth it for two usages in the same part of the same file.
internal/db/bundb/migrations/20240611190733_add_conversations.go
Outdated
Show resolved
Hide resolved
- Add context info for errors - Extract some common processor code into shared methods - Move conversation eligibility check ahead of populating conversation
I think as soon as you've resolved Kim's comments and tests pass, click the squerge button! 😍 |
fantastic work on this PR 👌 |
Description
Implements a Mastodon-compatible DM conversations API.
Closes #1312
Checklist
go fmt ./...
andgolangci-lint run
.TODO