Initial work on simplified state storage

This commit is contained in:
Neil Alexander 2021-04-14 17:30:37 +01:00
parent e08942fb00
commit a799847070
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
21 changed files with 540 additions and 1297 deletions

View file

@ -74,6 +74,24 @@ func (a StateEntry) LessThan(b StateEntry) bool {
return a.EventNID < b.EventNID
}
// Deduplicate takes a set of event NIDs and ensures that there are no
// duplicates. If there are then we dedupe them.
func DeduplicateEventNIDs(a []EventNID) []EventNID {
if len(a) < 2 {
return a
}
sort.SliceStable(a, func(i, j int) bool {
return a[i] < a[j]
})
for i := 0; i < len(a)-1; i++ {
if a[i] == a[i+1] {
a = append(a[:i], a[i+1:]...)
i--
}
}
return a
}
// Deduplicate takes a set of state entries and ensures that there are no
// duplicate (event type, state key) tuples. If there are then we dedupe
// them, making sure that the latest/highest NIDs are always chosen.
@ -151,18 +169,6 @@ const (
EmptyStateKeyNID = 1
)
// StateBlockNIDList is used to return the result of bulk StateBlockNID lookups from the database.
type StateBlockNIDList struct {
StateSnapshotNID StateSnapshotNID
StateBlockNIDs []StateBlockNID
}
// StateEntryList is used to return the result of bulk state entry lookups from the database.
type StateEntryList struct {
StateBlockNID StateBlockNID
StateEntries []StateEntry
}
// A MissingEventError is an error that happened because the roomserver was
// missing requested events from its database.
type MissingEventError string