Skip to content

Commit

Permalink
Only load full details for duplicate items
Browse files Browse the repository at this point in the history
App is way faster now!
  • Loading branch information
quasistoic committed Mar 7, 2023
1 parent e731c2f commit c00af92
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gui_kivy.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def refresh(self):
updated_items = []
for item in self.selected_set.items:
updated_items.append(app.op_api.get_item_details(item.item_id, force_refresh=True))
self.selected_set = op_api.DuplicateSet(updated_items)
self.selected_set = op_api.DuplicateSet(updated_items, op_api=app.op_api)
self.clear_set_details()
self.populate_set_details()

Expand Down
2 changes: 1 addition & 1 deletion gui_tkinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def refresh_duplicate_set(self, duplicate_set, frame):
for item in duplicate_set.items:
updated_items.append(self.op_api.get_item_details(item.item_id, force_refresh=True))
frame.destroy()
self.display_duplicate_set(op_api.DuplicateSet(updated_items))
self.display_duplicate_set(op_api.DuplicateSet(updated_items, op_api=self.op_api))

def display_duplicate_set(self, duplicate_set):
"""Display the selected duplicate set for management."""
Expand Down
19 changes: 11 additions & 8 deletions op_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def __iter__(self):
for i in self.items:
yield i

def __getitem__(self, i):
return self.items[i]

@classmethod
def from_json(cls, serialized_json):
raw_items = json.loads(serialized_json)
Expand Down Expand Up @@ -224,27 +227,27 @@ def mark_as_multiprofile(self, items):
def find_duplicates(self):
duplicates = []
duplicate_ids = set()
for i, item_id in enumerate(self.item_ids):
for i, details in enumerate(self.items):
item_id = details.item_id
if item_id in duplicate_ids:
logging.debug("Skipping %s because we know it's a duplicate.", item_id)
continue
logging.debug("Looking for duplicates of %s", item_id)
details = self.get_item_details(item_id)
if details and details.has_domains():
matching_items = []
for j in self.item_ids[i+1:]:
if j in duplicate_ids:
for j_details in self.items[i+1:]:
j_item_id = j_details.item_id
if j_item_id in duplicate_ids:
logging.debug(
"Skipping %s (inner loop) because we know it's a duplicate.", j)
"Skipping %s (inner loop) because we know it's a duplicate.", j_item_id)
continue
j_details = self.get_item_details(j)
if j_details.item_id == details.item_id:
continue
if not j_details.is_duplicate(details):
continue
matching_items.append(j_details)
if matching_items:
duplicate_set = DuplicateSet([details] + matching_items)
duplicate_set = DuplicateSet([details] + matching_items, op_api=self)
if duplicate_set.is_intentionally_multiprofile():
continue
duplicates.append(duplicate_set)
Expand Down Expand Up @@ -273,7 +276,7 @@ def force_full_details(self):
return

for i, item in enumerate(self.items[:]):
if i.has_full_details():
if item.has_full_details():
continue
new_item = self.op_api.get_item_details(item.item_id)
self.items[i] = new_item
Expand Down

1 comment on commit c00af92

@quasistoic
Copy link
Owner Author

@quasistoic quasistoic commented on c00af92 Mar 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closes #4.

Please sign in to comment.