Fix empty state snapshots

This commit is contained in:
Neil Alexander 2021-04-15 09:18:43 +01:00
parent a799847070
commit b7cf702a14
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
4 changed files with 5 additions and 9 deletions

View file

@ -463,7 +463,7 @@ func (v *StateResolution) CalculateAndStoreStateBeforeEvent(
// Load the state at the prev events.
prevStates, err := v.db.StateAtEventIDs(ctx, event.PrevEventIDs())
if err != nil {
return 0, err
return 0, fmt.Errorf("v.db.StateAtEventIDs: %w", err)
}
// The state before this event will be the state after the events that came before it.

View file

@ -99,6 +99,7 @@ func (s *stateStatements) BulkSelectState(
if err = rows.Scan(&stateNID, &eventNIDs); err != nil {
return nil, err
}
results[types.StateSnapshotNID(stateNID)] = []types.EventNID{}
for _, id := range eventNIDs {
results[types.StateSnapshotNID(stateNID)] = append(
results[types.StateSnapshotNID(stateNID)],

View file

@ -215,7 +215,7 @@ func (d *Database) StateEntries(
) ([]types.StateEntry, error) {
nids, err := d.StateTable.BulkSelectState(ctx, []types.StateSnapshotNID{stateSnapshotNID})
if err != nil {
return nil, fmt.Errorf("d.StateTable.BulkSelectState: %w", err)
return nil, fmt.Errorf("d.StateTable.BulkSelectState: %w (ID %d)", err, stateSnapshotNID)
}
state, ok := nids[stateSnapshotNID]
if !ok {

View file

@ -111,16 +111,11 @@ func (s *stateStatements) BulkSelectState(
if err = rows.Scan(&stateNID, &eventNIDJSON); err != nil {
return nil, fmt.Errorf("rows.Scan: %w", err)
}
var eventNIDs []int64
var eventNIDs []types.EventNID
if err = json.Unmarshal(eventNIDJSON, &eventNIDs); err != nil {
return nil, fmt.Errorf("json.Unmarshal: %w", err)
}
for _, id := range eventNIDs {
results[types.StateSnapshotNID(stateNID)] = append(
results[types.StateSnapshotNID(stateNID)],
types.EventNID(id),
)
}
results[types.StateSnapshotNID(stateNID)] = eventNIDs
}
if err = rows.Err(); err != nil {
return nil, fmt.Errorf("rows.Err: %w", err)