fix(message_persistence): ensure query cursor value is supplied where (#2898)

needed

Unfortunately, this one slipped through when introducing helper
functions to retrieve messages.

Sometimes, queries need an additional empty `cursor` value.
This commit is contained in:
r4bbit.eth 2022-10-07 19:38:28 +02:00 committed by GitHub
parent daee116878
commit 6c148389c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 7 deletions

2
go.mod
View File

@ -73,7 +73,7 @@ require (
go.uber.org/zap v1.22.0
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb
google.golang.org/protobuf v1.28.0 // indirect
google.golang.org/protobuf v1.28.0
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/go-playground/validator.v9 v9.31.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0

View File

@ -561,7 +561,7 @@ func (db sqlitePersistence) MessagesByIDs(ids []string) ([]*common.Message, erro
return nil, err
}
defer rows.Close()
return getMessagesFromScanRows(db, rows)
return getMessagesFromScanRows(db, rows, false)
}
// MessageByChatID returns all messages for a given chatID in descending order.
@ -762,7 +762,7 @@ func (db sqlitePersistence) AllMessageByChatIDWhichMatchTerm(chatID string, sear
return nil, err
}
defer rows.Close()
return getMessagesFromScanRows(db, rows)
return getMessagesFromScanRows(db, rows, true)
}
// AllMessagesFromChatsAndCommunitiesWhichMatchTerm returns all messages which match the search
@ -830,7 +830,7 @@ func (db sqlitePersistence) AllMessagesFromChatsAndCommunitiesWhichMatchTerm(com
return nil, err
}
defer rows.Close()
return getMessagesFromScanRows(db, rows)
return getMessagesFromScanRows(db, rows, true)
}
func (db sqlitePersistence) AllChatIDsByCommunity(communityID string) ([]string, error) {
@ -2255,7 +2255,7 @@ func SortByClock(msgs HasClocks) {
})
}
func getMessagesFromScanRows(db sqlitePersistence, rows *sql.Rows) ([]*common.Message, error) {
func getMessagesFromScanRows(db sqlitePersistence, rows *sql.Rows, withCursor bool) ([]*common.Message, error) {
messageIdx := make(map[string]*common.Message, 0)
for rows.Next() {
// There's a possibility of multiple rows per message if the
@ -2265,8 +2265,16 @@ func getMessagesFromScanRows(db sqlitePersistence, rows *sql.Rows) ([]*common.Me
// Hence, we make sure we're aggregating all attachments on a single
// common.Message
var message common.Message
if err := db.tableUserMessagesScanAllFields(rows, &message); err != nil {
return nil, err
if withCursor {
var cursor string
if err := db.tableUserMessagesScanAllFields(rows, &message, &cursor); err != nil {
return nil, err
}
} else {
if err := db.tableUserMessagesScanAllFields(rows, &message); err != nil {
return nil, err
}
}
if msg, ok := messageIdx[message.ID]; !ok {