Use pq arrays

This commit is contained in:
Neil Alexander 2021-04-16 16:41:43 +01:00
parent 2f41a4d2bf
commit 9f4ffe4c81
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -19,6 +19,7 @@ import (
"database/sql"
"fmt"
"github.com/lib/pq"
"github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/roomserver/types"
@ -70,10 +71,14 @@ func UpStateBlocksRefactor(tx *sql.Tx) error {
for snapshotrows.Next() {
var snapshot types.StateSnapshotNID
var room types.RoomNID
var blocksarray pq.Int64Array
var blocks []types.StateBlockNID
if err = snapshotrows.Scan(&snapshot, &room, &blocks); err != nil {
if err = snapshotrows.Scan(&snapshot, &room, &blocksarray); err != nil {
return fmt.Errorf("rows.Scan: %w", err)
}
for _, b := range blocksarray {
blocks = append(blocks, types.StateBlockNID(b))
}
var newblocks []types.StateBlockNID
for _, block := range blocks {
@ -84,6 +89,7 @@ func UpStateBlocksRefactor(tx *sql.Tx) error {
}
defer internal.CloseAndLogIfError(context.TODO(), blockrows, "rows.close() failed")
events := types.EventNIDs{}
var eventsarray pq.Int64Array
for blockrows.Next() {
var event types.EventNID
if err = blockrows.Scan(&event); err != nil {
@ -91,6 +97,9 @@ func UpStateBlocksRefactor(tx *sql.Tx) error {
}
events = append(events, event)
}
for _, e := range eventsarray {
events = append(events, types.EventNID(e))
}
events = events[:util.SortAndUnique(events)]
var blocknid types.StateBlockNID