-
Notifications
You must be signed in to change notification settings - Fork 0
β‘ Bolt: Optimize JSON file repository batch saves #71
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -46,15 +46,25 @@ def save_items(self, items: list[LearningItem]) -> None: | |||||||||||||||||
|
|
||||||||||||||||||
| storage = self._load_storage() | ||||||||||||||||||
| raw_items = storage.get("items", []) | ||||||||||||||||||
| existing_items = [] | ||||||||||||||||||
| if isinstance(raw_items, list): | ||||||||||||||||||
| existing_items = [ | ||||||||||||||||||
| _item_from_dict(entry) for entry in raw_items if isinstance(entry, dict) | ||||||||||||||||||
| ] | ||||||||||||||||||
| by_id = {existing.id: existing for existing in existing_items} | ||||||||||||||||||
| for item in items: | ||||||||||||||||||
| by_id[item.id] = item | ||||||||||||||||||
| storage["items"] = [_item_to_dict(entry) for entry in by_id.values()] | ||||||||||||||||||
| if not isinstance(raw_items, list): | ||||||||||||||||||
| raw_items = [] | ||||||||||||||||||
|
|
||||||||||||||||||
| # Performance optimization: | ||||||||||||||||||
| # Instead of fully deserializing all items (O(N) CPU overhead), | ||||||||||||||||||
| # we convert the new items to dicts and update the raw JSON list in-place. | ||||||||||||||||||
| # This speeds up partial batch updates significantly when the repository is large. | ||||||||||||||||||
| items_to_save = {str(item.id): _item_to_dict(item) for item in items} | ||||||||||||||||||
|
|
||||||||||||||||||
| for i, entry in enumerate(raw_items): | ||||||||||||||||||
| if isinstance(entry, dict): | ||||||||||||||||||
| entry_id = str(entry.get("id")) | ||||||||||||||||||
| if entry_id in items_to_save: | ||||||||||||||||||
| raw_items[i] = items_to_save.pop(entry_id) | ||||||||||||||||||
|
Comment on lines
+60
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current logic for
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Removing the entry from Useful? React with πΒ / π. |
||||||||||||||||||
|
|
||||||||||||||||||
| for new_item in items_to_save.values(): | ||||||||||||||||||
| raw_items.append(new_item) | ||||||||||||||||||
|
|
||||||||||||||||||
| storage["items"] = raw_items | ||||||||||||||||||
| self._save_storage(storage) | ||||||||||||||||||
|
|
||||||||||||||||||
| def list_attempts(self) -> list[Attempt]: | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The date "2025-03-01" appears to be in the future. Please update this to reflect the actual date the learning was made or a past date to maintain accuracy in the learning log.