Correct account data position mapping

This commit is contained in:
Neil Alexander 2022-04-27 14:45:51 +01:00
parent f023cdf8c4
commit 6ee8507955
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
2 changed files with 14 additions and 7 deletions

View File

@ -105,7 +105,7 @@ func (s *accountDataStatements) SelectAccountDataInRange(
accountDataEventFilter *gomatrixserverlib.EventFilter, accountDataEventFilter *gomatrixserverlib.EventFilter,
) (data map[string][]string, pos types.StreamPosition, err error) { ) (data map[string][]string, pos types.StreamPosition, err error) {
data = make(map[string][]string) data = make(map[string][]string)
pos = r.Low() pos = r.High()
rows, err := s.selectAccountDataInRangeStmt.QueryContext(ctx, userID, r.Low(), r.High(), rows, err := s.selectAccountDataInRangeStmt.QueryContext(ctx, userID, r.Low(), r.High(),
pq.StringArray(filterConvertTypeWildcardToSQL(accountDataEventFilter.Types)), pq.StringArray(filterConvertTypeWildcardToSQL(accountDataEventFilter.Types)),
@ -120,6 +120,7 @@ func (s *accountDataStatements) SelectAccountDataInRange(
var dataType string var dataType string
var roomID string var roomID string
var id types.StreamPosition var id types.StreamPosition
var highest types.StreamPosition
for rows.Next() { for rows.Next() {
if err = rows.Scan(&id, &roomID, &dataType); err != nil { if err = rows.Scan(&id, &roomID, &dataType); err != nil {
@ -131,10 +132,13 @@ func (s *accountDataStatements) SelectAccountDataInRange(
} else { } else {
data[roomID] = []string{dataType} data[roomID] = []string{dataType}
} }
if id > pos { if id > highest {
pos = id highest = id
} }
} }
if highest < pos {
pos = highest
}
return data, pos, rows.Err() return data, pos, rows.Err()
} }

View File

@ -96,7 +96,7 @@ func (s *accountDataStatements) SelectAccountDataInRange(
r types.Range, r types.Range,
filter *gomatrixserverlib.EventFilter, filter *gomatrixserverlib.EventFilter,
) (data map[string][]string, pos types.StreamPosition, err error) { ) (data map[string][]string, pos types.StreamPosition, err error) {
pos = r.Low() pos = r.High()
data = make(map[string][]string) data = make(map[string][]string)
stmt, params, err := prepareWithFilters( stmt, params, err := prepareWithFilters(
s.db, nil, selectAccountDataInRangeSQL, s.db, nil, selectAccountDataInRangeSQL,
@ -116,6 +116,7 @@ func (s *accountDataStatements) SelectAccountDataInRange(
var dataType string var dataType string
var roomID string var roomID string
var id types.StreamPosition var id types.StreamPosition
var highest types.StreamPosition
for rows.Next() { for rows.Next() {
if err = rows.Scan(&id, &roomID, &dataType); err != nil { if err = rows.Scan(&id, &roomID, &dataType); err != nil {
@ -127,11 +128,13 @@ func (s *accountDataStatements) SelectAccountDataInRange(
} else { } else {
data[roomID] = []string{dataType} data[roomID] = []string{dataType}
} }
if id > pos { if id > highest {
pos = id highest = id
} }
} }
if highest < pos {
pos = highest
}
return data, pos, nil return data, pos, nil
} }