fix(store): limit dbPageSize (#1018)

This commit is contained in:
Daniel Kaiser 2022-06-23 17:05:48 +02:00 committed by GitHub
parent cf1a7c3074
commit a2749c4a52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -267,8 +267,13 @@ method getAll*(db: WakuMessageStore, onData: message_store.DataProc): MessageSto
ok gotMessages ok gotMessages
proc adjustDbPageSize(dbPageSize: uint64, matchCount: uint64, returnPageSize: uint64): uint64 {.inline.} = proc adjustDbPageSize(dbPageSize: uint64, matchCount: uint64, returnPageSize: uint64): uint64 {.inline.} =
var ret = if matchCount < 2: dbPageSize * returnPageSize const maxDbPageSize: uint64 = 20000 # the maximum DB page size is limited to prevent excessive use of memory in case of very sparse or non-matching filters. TODO: dynamic, adjust to available memory
if dbPageSize >= maxDbPageSize:
return maxDbPageSize
var ret =
if matchCount < 2: dbPageSize * returnPageSize
else: dbPageSize * (returnPageSize div matchCount) else: dbPageSize * (returnPageSize div matchCount)
ret = min(ret, maxDbPageSize)
trace "dbPageSize adjusted to: ", ret trace "dbPageSize adjusted to: ", ret
ret ret