mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-26 15:08:28 +00:00
Fix single prev state update
This commit is contained in:
parent
7b2e141fa9
commit
921b0a432e
1 changed files with 8 additions and 19 deletions
|
@ -508,8 +508,14 @@ func (v *StateResolution) CalculateAndStoreStateAfterEvents(
|
||||||
return 0, fmt.Errorf("v.db.StateEntries: %w", err)
|
return 0, fmt.Errorf("v.db.StateEntries: %w", err)
|
||||||
}
|
}
|
||||||
found := false
|
found := false
|
||||||
for _, s := range oldState {
|
for i := range oldState {
|
||||||
if s.EventNID == prevState.StateEntry.EventNID {
|
if oldState[i].EventNID == prevState.EventNID {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if oldState[i].EventStateKeyNID == prevState.EventStateKeyNID &&
|
||||||
|
oldState[i].EventTypeNID == prevState.EventTypeNID {
|
||||||
|
oldState[i] = prevState.StateEntry
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -562,13 +568,6 @@ func (v *StateResolution) CalculateAndStoreStateAfterEvents(
|
||||||
return stateNID, nil
|
return stateNID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// maxStateBlockNIDs is the maximum number of state data blocks to use to encode a snapshot of room state.
|
|
||||||
// Increasing this number means that we can encode more of the state changes as simple deltas which means that
|
|
||||||
// we need fewer entries in the state data table. However making this number bigger will increase the size of
|
|
||||||
// the rows in the state table itself and will require more index lookups when retrieving a snapshot.
|
|
||||||
// TODO: Tune this to get the right balance between size and lookup performance.
|
|
||||||
const maxStateBlockNIDs = 64
|
|
||||||
|
|
||||||
// calculateAndStoreStateAfterManyEvents finds the room state after the given events.
|
// calculateAndStoreStateAfterManyEvents finds the room state after the given events.
|
||||||
// This handles the slow path of calculateAndStoreStateAfterEvents for when there is more than one event.
|
// This handles the slow path of calculateAndStoreStateAfterEvents for when there is more than one event.
|
||||||
// Stores the resulting state and returns a numeric ID for the snapshot.
|
// Stores the resulting state and returns a numeric ID for the snapshot.
|
||||||
|
@ -977,16 +976,6 @@ func UniqueStateSnapshotNIDs(nids []types.StateSnapshotNID) []types.StateSnapsho
|
||||||
return nids[:util.SortAndUnique(stateNIDSorter(nids))]
|
return nids[:util.SortAndUnique(stateNIDSorter(nids))]
|
||||||
}
|
}
|
||||||
|
|
||||||
type stateBlockNIDSorter []types.StateBlockNID
|
|
||||||
|
|
||||||
func (s stateBlockNIDSorter) Len() int { return len(s) }
|
|
||||||
func (s stateBlockNIDSorter) Less(i, j int) bool { return s[i] < s[j] }
|
|
||||||
func (s stateBlockNIDSorter) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
|
||||||
|
|
||||||
func uniqueStateBlockNIDs(nids []types.StateBlockNID) []types.StateBlockNID {
|
|
||||||
return nids[:util.SortAndUnique(stateBlockNIDSorter(nids))]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Map from event type, state key tuple to numeric event ID.
|
// Map from event type, state key tuple to numeric event ID.
|
||||||
// Implemented using binary search on a sorted array.
|
// Implemented using binary search on a sorted array.
|
||||||
type stateEntryMap []types.StateEntry
|
type stateEntryMap []types.StateEntry
|
||||||
|
|
Loading…
Reference in a new issue