Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CASMCMS-9225: Do not use itertools.batched #415

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [2.0.49] - 2024-12-19
### Fixed
- Use correct path to requests_retry_session module
- Do not use `itertools.batched`, because it is not available in this Python version.

## [2.0.48] - 2024-12-18
### Changed
Expand Down
7 changes: 4 additions & 3 deletions src/bos/server/redis_db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
from itertools import batched
import json
import logging
from typing import Callable
Expand Down Expand Up @@ -111,9 +110,11 @@ def iter_values(self):
"""
Iterate through every item in the database. Parse each item as JSON and yield it.
"""
for next_keys in batched(self.client.scan_iter(), 500):
for datastr in self.client.mget(next_keys):
all_keys = list(self.client.scan_iter())
while all_keys:
for datastr in self.client.mget(all_keys[:500]):
yield json.loads(datastr) if datastr else None
all_keys = all_keys[500:]

def put(self, key, new_data):
"""Put data in to the database, replacing any old data."""
Expand Down
Loading