mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-23 14:53:10 -06:00
Hopefully fix the event references updates
This commit is contained in:
parent
2604b0b8ec
commit
43403bf920
|
|
@ -27,10 +27,15 @@ import (
|
||||||
"github.com/matrix-org/dendrite/roomserver/types"
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: previous_reference_sha256 was NOT NULL before but it broke sytest because
|
||||||
|
// sytest sends no SHA256 sums in the prev_events references in the soft-fail tests.
|
||||||
|
// In Postgres an empty BYTEA field is not NULL so it's fine there. In SQLite it
|
||||||
|
// seems to care that it's empty and therefore hits a NOT NULL constraint on insert.
|
||||||
|
// We should really work out what the right thing to do here is.
|
||||||
const previousEventSchema = `
|
const previousEventSchema = `
|
||||||
CREATE TABLE IF NOT EXISTS roomserver_previous_events (
|
CREATE TABLE IF NOT EXISTS roomserver_previous_events (
|
||||||
previous_event_id TEXT NOT NULL,
|
previous_event_id TEXT NOT NULL,
|
||||||
previous_reference_sha256 BLOB NOT NULL,
|
previous_reference_sha256 BLOB,
|
||||||
event_nids TEXT NOT NULL,
|
event_nids TEXT NOT NULL,
|
||||||
UNIQUE (previous_event_id, previous_reference_sha256)
|
UNIQUE (previous_event_id, previous_reference_sha256)
|
||||||
);
|
);
|
||||||
|
|
@ -90,17 +95,24 @@ func (s *previousEventStatements) InsertPreviousEvent(
|
||||||
eventNID types.EventNID,
|
eventNID types.EventNID,
|
||||||
) error {
|
) error {
|
||||||
var eventNIDs string
|
var eventNIDs string
|
||||||
|
eventNIDAsString := fmt.Sprintf("%d", eventNID)
|
||||||
selectStmt := sqlutil.TxStmt(txn, s.selectPreviousEventExistsStmt)
|
selectStmt := sqlutil.TxStmt(txn, s.selectPreviousEventExistsStmt)
|
||||||
err := selectStmt.QueryRowContext(ctx, previousEventID, previousEventReferenceSHA256).Scan(&eventNIDs)
|
err := selectStmt.QueryRowContext(ctx, previousEventID, previousEventReferenceSHA256).Scan(&eventNIDs)
|
||||||
if err != sql.ErrNoRows {
|
if err != sql.ErrNoRows {
|
||||||
return fmt.Errorf("selectStmt.QueryRowContext.Scan: %w", err)
|
return fmt.Errorf("selectStmt.QueryRowContext.Scan: %w", err)
|
||||||
}
|
}
|
||||||
for _, nid := range strings.Split(eventNIDs, ",") {
|
var nids []string
|
||||||
if nid == fmt.Sprintf("%d", eventNID) {
|
if eventNIDs != "" {
|
||||||
return nil
|
nids = strings.Split(eventNIDs, ",")
|
||||||
|
for _, nid := range nids {
|
||||||
|
if nid == eventNIDAsString {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
eventNIDs = strings.Join(append(nids, eventNIDAsString), ",")
|
||||||
|
} else {
|
||||||
|
eventNIDs = eventNIDAsString
|
||||||
}
|
}
|
||||||
eventNIDs = fmt.Sprintf("%s,%d", eventNIDs, eventNID)
|
|
||||||
insertStmt := sqlutil.TxStmt(txn, s.insertPreviousEventStmt)
|
insertStmt := sqlutil.TxStmt(txn, s.insertPreviousEventStmt)
|
||||||
_, err = insertStmt.ExecContext(
|
_, err = insertStmt.ExecContext(
|
||||||
ctx, previousEventID, previousEventReferenceSHA256, eventNIDs,
|
ctx, previousEventID, previousEventReferenceSHA256, eventNIDs,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue