nwaku/waku/utils/tableutils.nim
NagyZoltanPeter c3358409bb
chore: Refactor of FilterV2 subscription management with Time-to-live maintenance (#2341)
* Refactor of FilterV2 subscription handling and maintenance with addition subscription time-to-live support.
Fixed all tests and reworked where subscription handling changes needed it.
Adapted REST API /admin filter subscription retrieve to new filter subscription structure.

* Fix tests and PR comments

* Added filter v2 subscription timeout tests and fixed

* Fix review comments and suggestions. No functional change.

* Remove leftover echoes from test_rest_admin

* Fix failed legacy filter tests due to separation of mounting the filters.

* Small fixes, fix naming typo, removed duplicated checks in test
2024-01-16 17:27:40 +01:00

36 lines
865 B
Nim

import std/tables,
stew/objects,
stew/templateutils
template keepItIf*[A, B](tableParam: var Table[A, B], itPredicate: untyped) =
bind evalTemplateParamOnce
evalTemplateParamOnce(tableParam, t):
var itemsToDelete: seq[A]
var key {.inject.} : A
var val {.inject.} : B
for k, v in t.mpairs():
key = k
val = v
if not itPredicate:
itemsToDelete.add(key)
for item in itemsToDelete:
t.del(item)
template keepItIf*[A, B](tableParam: var TableRef[A, B], itPredicate: untyped) =
bind evalTemplateParamOnce
evalTemplateParamOnce(tableParam, t):
var itemsToDelete: seq[A]
let key {.inject.} : A
let val {.inject.} : B
for k, v in t[].mpairs():
key = k
val = v
if not itPredicate:
itemsToDelete.add(key)
for item in itemsToDelete:
t[].del(item)