mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-28 12:23:32 -06:00
[bugfix] fix issues with postgres array serialization (#4295)
thank you to @kipvandenbos -erino for figuring this out! Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4295 Co-authored-by: kim <grufwub@gmail.com> Co-committed-by: kim <grufwub@gmail.com>
This commit is contained in:
parent
700bd69828
commit
39b11dbfb6
4 changed files with 38 additions and 2 deletions
|
|
@ -110,12 +110,16 @@ func init() {
|
|||
return gtserror.Newf("error selecting %T ids: %w", data.Model, err)
|
||||
}
|
||||
|
||||
// Convert related IDs to bun array
|
||||
// type for serialization in query.
|
||||
arrIDs := bunArrayType(tx, relatedIDs)
|
||||
|
||||
// Now update the relevant filter
|
||||
// row to contain these related IDs.
|
||||
if _, err := tx.NewUpdate().
|
||||
Model((*newmodel.Filter)(nil)).
|
||||
Where("? = ?", bun.Ident("id"), filterID).
|
||||
Set("? = ?", bun.Ident(col), relatedIDs).
|
||||
Set("? = ?", bun.Ident(col), arrIDs).
|
||||
Exec(ctx); err != nil {
|
||||
return gtserror.Newf("error updating filters.%s ids: %w", col, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,10 +34,24 @@ import (
|
|||
"github.com/uptrace/bun"
|
||||
"github.com/uptrace/bun/dialect"
|
||||
"github.com/uptrace/bun/dialect/feature"
|
||||
"github.com/uptrace/bun/dialect/pgdialect"
|
||||
"github.com/uptrace/bun/dialect/sqltype"
|
||||
"github.com/uptrace/bun/schema"
|
||||
)
|
||||
|
||||
// bunArrayType wraps the given type in a pgdialect.Array
|
||||
// if needed, which postgres wants for serializing arrays.
|
||||
func bunArrayType(db bun.IDB, arr any) any {
|
||||
switch db.Dialect().Name() {
|
||||
case dialect.SQLite:
|
||||
return arr // return as-is
|
||||
case dialect.PG:
|
||||
return pgdialect.Array(arr)
|
||||
default:
|
||||
panic("unreachable")
|
||||
}
|
||||
}
|
||||
|
||||
// doWALCheckpoint attempt to force a WAL file merge on SQLite3,
|
||||
// which can be useful given how much can build-up in the WAL.
|
||||
//
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue