Fix state block schema a bit
This commit is contained in:
parent
8bb8642560
commit
7a7be4f0ac
|
@ -28,7 +28,7 @@ import (
|
|||
|
||||
const stateDataSchema = `
|
||||
CREATE TABLE IF NOT EXISTS roomserver_state_block (
|
||||
state_block_nid INTEGER NOT NULL,
|
||||
state_block_nid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
event_type_nid INTEGER NOT NULL,
|
||||
event_state_key_nid INTEGER NOT NULL,
|
||||
event_nid INTEGER NOT NULL,
|
||||
|
@ -41,7 +41,10 @@ const insertStateDataSQL = "" +
|
|||
" VALUES ($1, $2, $3, $4)"
|
||||
|
||||
const selectNextStateBlockNIDSQL = `
|
||||
SELECT seq+1 FROM sqlite_sequence WHERE name = 'roomserver_state_block'
|
||||
SELECT COALESCE((
|
||||
SELECT seq AS state_block_nid FROM sqlite_sequence
|
||||
WHERE name = 'roomserver_state_block'), 0
|
||||
) AS state_block_nid
|
||||
`
|
||||
|
||||
// Bulk state lookup by numeric state block ID.
|
||||
|
|
|
@ -88,7 +88,7 @@ func (s *stateSnapshotStatements) bulkSelectStateBlockNIDs(
|
|||
for i := range stateNIDs {
|
||||
nids[i] = int64(stateNIDs[i])
|
||||
}
|
||||
rows, err := s.bulkSelectStateBlockNIDsStmt.QueryContext(ctx, pq.Int64Array(nids))
|
||||
rows, err := s.bulkSelectStateBlockNIDsStmt.QueryContext(ctx, sqliteIn(pq.Int64Array(nids)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package sqlite3
|
|||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
|
@ -245,11 +244,9 @@ func (d *Database) AddState(
|
|||
if len(state) > 0 {
|
||||
stateBlockNID, err := d.statements.selectNextStateBlockNID(ctx)
|
||||
if err != nil {
|
||||
fmt.Println("d.statements.selectNextStateBlockNID", err)
|
||||
return 0, err
|
||||
}
|
||||
if err = d.statements.bulkInsertStateData(ctx, stateBlockNID, state); err != nil {
|
||||
fmt.Println("d.statements.bulkInsertStateData", err)
|
||||
return 0, err
|
||||
}
|
||||
stateBlockNIDs = append(stateBlockNIDs[:len(stateBlockNIDs):len(stateBlockNIDs)], stateBlockNID)
|
||||
|
|
Loading…
Reference in a new issue