Repository navigation
Fix #380: drop empty moving-window keys in MemoryStorage.__expire_events - #383
Open
zheng-guannan577 wants to merge 3 commits into
Open
zheng-guannan577 wants to merge 3 commits into
zheng-guannan577 wants to merge 3 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #380.
When
MemoryStorage.__expire_eventsremoves the last expiredmoving-window event for a key, it now removes the empty entry from
self.eventsas well, instead of leavingkey: []behind. Along-lived storage instance therefore no longer retains one empty
entry per distinct moving-window key, and later cleanup passes no
longer scan those empty entries.
This mirrors the asynchronous implementation
(
limits/aio/storage/memory.py), which already pops the empty evententry at the same point.
Changes
limits/storage/memory.py: one line in__expire_events—self.events.pop(key, None)next to the existingself.locks.pop(key, None).tests/storage/test_memory.py: newTestMovingWindowExpirycovering the issue's reproduction (1,000 keys expiring to an empty
eventsdict), mixed live/expired keys, repeated cleanup, and reuseof an expired key afterwards.
Tests
len(storage.events)goes from 1000(before) to 0 (after).
pytest tests/storage/test_memory.py— 3 passed.tests/test_storage_schema.py,tests/storage/,tests/aio/storage/,tests/test_storage.py,tests/test_strategy.py,tests/test_limits.py, backend-markedtests deselected) — 85 passed, 0 failed.
ruff checkandruff format --checkpass on the changed files.Notes
automated testing of this change.
submitted for review.