Drop oldest-lastSeen entries until the map holds at most `max`.
(map, max)
| 91 | |
| 92 | /** Drop oldest-lastSeen entries until the map holds at most `max`. */ |
| 93 | function pruneByLastSeen(map, max) { |
| 94 | const keys = Object.keys(map); |
| 95 | if (keys.length <= max) return; |
| 96 | keys.sort((a, b) => |
| 97 | String(map[a].lastSeen || '').localeCompare(String(map[b].lastSeen || '')) |
| 98 | ); |
| 99 | for (const key of keys.slice(0, keys.length - max)) { |
| 100 | delete map[key]; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | // -- State management --------------------------------------------------------- |
| 105 |