use `BTreeMap.drain_filter` for selective db update, rather than clearing everything and replenishing. ref: rust-lang / rust / 70530