Skip to content

Commit 1e48b15

Browse files
dsblankNick-Hall
authored andcommitted
Add optimization to HasIdOf rules
1 parent 05577a9 commit 1e48b15

File tree

10 files changed

+79
-2
lines changed

10 files changed

+79
-2
lines changed

gramps/gen/filters/rules/_hasgrampsid.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
# Typing modules
4242
#
4343
# -------------------------------------------------------------------------
44-
from ...lib.primaryobj import PrimaryObject
44+
from typing import Set
45+
from ...types import PrimaryObjectHandle, PrimaryObject
4546
from ...db import Database
4647

4748

@@ -57,10 +58,14 @@ class HasGrampsId(Rule):
5758
name = "Object with <Id>"
5859
description = "Matches objects with a specified Gramps ID"
5960
category = _("General filters")
61+
selected_handles: Set[PrimaryObjectHandle] = set([])
6062

6163
def apply_to_one(self, db: Database, obj: PrimaryObject) -> bool:
6264
"""
6365
apply the rule on the obj.
6466
return true if the rule passes, false otherwise.
6567
"""
66-
return obj.gramps_id == self.list[0]
68+
return obj.handle in self.selected_handles
69+
70+
def reset(self):
71+
self.selected_handles.clear()

gramps/gen/filters/rules/citation/_hasidof.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#
2626
# -------------------------------------------------------------------------
2727
from ....const import GRAMPS_LOCALE as glocale
28+
from ....db import Database
2829

2930
_ = glocale.translation.gettext
3031

@@ -46,3 +47,10 @@ class HasIdOf(HasGrampsId):
4647

4748
name = _("Citation with <Id>")
4849
description = _("Matches a citation with a specified Gramps ID")
50+
51+
def prepare(self, db: Database, user):
52+
data = db._get_raw_citation_from_id_data(self.list[0])
53+
if data:
54+
self.selected_handles = set([data.handle])
55+
else:
56+
self.selected_handles = set([])

gramps/gen/filters/rules/event/_hasidof.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#
2525
# -------------------------------------------------------------------------
2626
from ....const import GRAMPS_LOCALE as glocale
27+
from ....db import Database
2728

2829
_ = glocale.translation.gettext
2930

@@ -45,3 +46,10 @@ class HasIdOf(HasGrampsId):
4546

4647
name = _("Event with <Id>")
4748
description = _("Matches an event with a specified Gramps ID")
49+
50+
def prepare(self, db: Database, user):
51+
data = db._get_raw_event_from_id_data(self.list[0])
52+
if data:
53+
self.selected_handles = set([data.handle])
54+
else:
55+
self.selected_handles = set([])

gramps/gen/filters/rules/family/_hasidof.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#
2525
# -------------------------------------------------------------------------
2626
from ....const import GRAMPS_LOCALE as glocale
27+
from ....db import Database
2728

2829
_ = glocale.translation.gettext
2930

@@ -45,3 +46,10 @@ class HasIdOf(HasGrampsId):
4546

4647
name = _("Family with <Id>")
4748
description = _("Matches a family with a specified Gramps ID")
49+
50+
def prepare(self, db: Database, user):
51+
data = db._get_raw_family_from_id_data(self.list[0])
52+
if data:
53+
self.selected_handles = set([data.handle])
54+
else:
55+
self.selected_handles = set([])

gramps/gen/filters/rules/media/_hasidof.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#
2525
# -------------------------------------------------------------------------
2626
from ....const import GRAMPS_LOCALE as glocale
27+
from ....db import Database
2728

2829
_ = glocale.translation.gettext
2930

@@ -45,3 +46,10 @@ class HasIdOf(HasGrampsId):
4546

4647
name = _("Media object with <Id>")
4748
description = _("Matches a media object with a specified Gramps ID")
49+
50+
def prepare(self, db: Database, user):
51+
data = db._get_raw_media_from_id_data(self.list[0])
52+
if data:
53+
self.selected_handles = set([data.handle])
54+
else:
55+
self.selected_handles = set([])

gramps/gen/filters/rules/note/_hasidof.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#
2525
# -------------------------------------------------------------------------
2626
from ....const import GRAMPS_LOCALE as glocale
27+
from ....db import Database
2728

2829
_ = glocale.translation.gettext
2930

@@ -45,3 +46,10 @@ class HasIdOf(HasGrampsId):
4546

4647
name = _("Note with <Id>")
4748
description = _("Matches a note with a specified Gramps ID")
49+
50+
def prepare(self, db: Database, user):
51+
data = db._get_raw_note_from_id_data(self.list[0])
52+
if data:
53+
self.selected_handles = set([data.handle])
54+
else:
55+
self.selected_handles = set([])

gramps/gen/filters/rules/person/_hasidof.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#
2525
# -------------------------------------------------------------------------
2626
from ....const import GRAMPS_LOCALE as glocale
27+
from ....db import Database
2728

2829
_ = glocale.translation.gettext
2930

@@ -45,3 +46,10 @@ class HasIdOf(HasGrampsId):
4546

4647
name = _("Person with <Id>")
4748
description = _("Matches person with a specified Gramps ID")
49+
50+
def prepare(self, db: Database, user):
51+
data = db._get_raw_person_from_id_data(self.list[0])
52+
if data:
53+
self.selected_handles = set([data.handle])
54+
else:
55+
self.selected_handles = set([])

gramps/gen/filters/rules/place/_hasidof.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#
2525
# -------------------------------------------------------------------------
2626
from ....const import GRAMPS_LOCALE as glocale
27+
from ....db import Database
2728

2829
_ = glocale.translation.gettext
2930

@@ -45,3 +46,10 @@ class HasIdOf(HasGrampsId):
4546

4647
name = _("Place with <Id>")
4748
description = _("Matches a place with a specified Gramps ID")
49+
50+
def prepare(self, db: Database, user):
51+
data = db._get_raw_place_from_id_data(self.list[0])
52+
if data:
53+
self.selected_handles = set([data.handle])
54+
else:
55+
self.selected_handles = set([])

gramps/gen/filters/rules/repository/_hasidof.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#
2525
# -------------------------------------------------------------------------
2626
from ....const import GRAMPS_LOCALE as glocale
27+
from ....db import Database
2728

2829
_ = glocale.translation.gettext
2930

@@ -45,3 +46,10 @@ class HasIdOf(HasGrampsId):
4546

4647
name = _("Repository with <Id>")
4748
description = _("Matches a repository with a specified Gramps ID")
49+
50+
def prepare(self, db: Database, user):
51+
data = db._get_raw_repository_from_id_data(self.list[0])
52+
if data:
53+
self.selected_handles = set([data.handle])
54+
else:
55+
self.selected_handles = set([])

gramps/gen/filters/rules/source/_hasidof.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#
2525
# -------------------------------------------------------------------------
2626
from ....const import GRAMPS_LOCALE as glocale
27+
from ....db import Database
2728

2829
_ = glocale.translation.gettext
2930

@@ -45,3 +46,10 @@ class HasIdOf(HasGrampsId):
4546

4647
name = _("Source with <Id>")
4748
description = _("Matches a source with a specified Gramps ID")
49+
50+
def prepare(self, db: Database, user):
51+
data = db._get_raw_source_from_id_data(self.list[0])
52+
if data:
53+
self.selected_handles = set([data.handle])
54+
else:
55+
self.selected_handles = set([])

0 commit comments

Comments
 (0)