Whole file
msiemens/tinydb
The author described this change as “Don't add keys to LRU cache if lookup fails (closes #87)”. It counts as a record because the check below fails on the code as it stood at 1f411be06 and passes on 7af4bf50c, with nothing else changed between the two runs.
Projectmsiemens/tinydb
Fix saved2016-01-03
Sharing licenceMIT · LICENSE
Change size+5 −3
What the code was meant to do, written into the code itself as a save note
Don't add keys to LRU cache if lookup fails (closes #87)
The change
| 29 | 29 | ||
| 30 | 30 | def refresh(self, key): | |
| 31 | 31 | """ | |
| 32 | - | Push a key to the head of the LRU queue | |
| 32 | + | Push a key to the tail of the LRU queue | |
| 33 | 33 | """ | |
| 34 | 34 | if key in self.lru: | |
| 35 | 35 | self.lru.remove(key) | |
| 36 | 36 | self.lru.append(key) | |
| 37 | 37 | ||
| 38 | 38 | def get(self, key, default=None): | |
| 39 | + | item = super(LRUCache, self).get(key, default) | |
| 39 | 40 | self.refresh(key) | |
| 40 | 41 | ||
| 41 | - | return super(LRUCache, self).get(key, default) | |
| 42 | + | return item | |
| 42 | 43 | ||
| 43 | 44 | def __getitem__(self, key): | |
| 45 | + | item = super(LRUCache, self).__getitem__(key) | |
| 44 | 46 | self.refresh(key) | |
| 45 | 47 | ||
| 46 | - | return super(LRUCache, self).__getitem__(key) | |
| 48 | + | return item | |
| 47 | 49 | ||
| 48 | 50 | def __setitem__(self, key, value): | |
| 49 | 51 | super(LRUCache, self).__setitem__(key, value) |
The check that tells the two apart
fail→pass·tests/test_utils.py::test_lru_cache
Check file tests/test_utils.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it1f411be06776f8647be7549af94c28ef2d3cdac6
Broken version dated2015-12-31
Moduletinydb.utils
Units changedLRUCache
Fingerprint9ae6be54afd5b53c
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in msiemens/tinydb
- 2015-02-03CachingMiddleware
- 2014-10-14Fix _last_id after opening old DB (closes #34)
- 2014-07-26fix bug where LRU cache is not cleared on delete