Skip to content

Commit

Permalink
Fix logic bug; add preparation progress; progress matches actual count
Browse files Browse the repository at this point in the history
  • Loading branch information
dsblank committed Nov 19, 2024
1 parent ec72673 commit e3f7487
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions gramps/gen/filters/_genericfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ def apply_logical_op_to_all(
self, db, id_list, apply_logical_op, user=None, tupleind=None, tree=False
):
final_list = []
if user:
user.begin_progress(_("Filter"), _("Applying ..."), self.get_number(db))

def intersection(sets):
if sets:
Expand All @@ -209,7 +207,7 @@ def union(sets):
# Optimiziation
# ------------------------------------------------------
all_maps = []
self.walk_filters(self, self.invert, all_maps)
self.walk_filters(self, False, all_maps)
LOG.debug("number of maps to consider: %s", len(all_maps))
handles_in = None
handles_out = set()
Expand All @@ -235,35 +233,48 @@ def union(sets):
LOG.debug("optimizer handles_in: %s", len(handles_in) if handles_in else 0)
if id_list is None:
if handles_in is not None:
if user:
user.begin_progress(_("Filter"), _("Applying ..."), len(handles))

# Use these rather than going through entire database
for handle in handles_in:
if user:
user.step_progress()

if handle is None:
continue

json_data = self.get_raw_data(db, handle)

if user:
user.step_progress()

if apply_logical_op(db, json_data, self.flist) != self.invert:
final_list.append(json_data["handle"])

else:
with (
self.get_tree_cursor(db) if tree else self.get_cursor(db)
) as cursor:
for handle, data in cursor:
if handle in handles_out:
continue
if user:
user.begin_progress(
_("Filter"), _("Applying ..."), self.get_number(db)
)

for handle, data in cursor:
if user:
user.step_progress()

if handle in handles_out:
continue

if apply_logical_op(db, data, self.flist) != self.invert:
final_list.append(handle)

else:
if user:
user.begin_progress(_("Filter"), _("Applying ..."), len(id_list))
for data in id_list:
if user:
user.step_progress()

if tupleind is None:
handle = data
else:
Expand All @@ -277,9 +288,6 @@ def union(sets):

json_data = self.get_raw_data(db, handle)

if user:
user.step_progress()

if apply_logical_op(db, json_data, self.flist) != self.invert:
final_list.append(data)

Expand Down Expand Up @@ -337,9 +345,16 @@ def apply_to_all(self, db, id_list=None, tupleind=None, user=None, tree=False):
if id_list not given, all items in the database that
match the filter are returned as a list of handles
"""
if user:
user.begin_progress(_("Filter"), _("Preparing ..."), len(self.flist))

for rule in self.flist:
rule.requestprepare(db, user)
if user:
user.step_progress()

if user:
user.end_progress()

if self.logical_op == "and":
apply_logical_op = self.and_test
Expand Down

0 comments on commit e3f7487

Please sign in to comment.