-
Notifications
You must be signed in to change notification settings - Fork 424
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
Teach GrampsType.set() to work with a dict #1825
base: master
Are you sure you want to change the base?
Conversation
@dsblank I'd appreciate your review of this
|
The same problem exists with notes and repositories views. |
@stevenyoungs good catch! Yes, you are correct... another place where the array/blob representation had leaked into other parts of the code. What would be better, though, would be to not create an object if it isn't necessary, and just get the results needed. That might be something like: def get_event_type_from_raw_data(data):
return what_ever_is_needed |
Can't we just |
How about this, which allows us to avoid building the object, and also hides the detail inside a static method in EventType
and then it becomes
Thoughts? |
I'm going to do some timing tests between turning just the data["type"] into an instance, versus your static method. If they are not that significantly different, I think we'd just create an object, rather than having to have yet another method to access the data. |
Timing tests comparing converting to an object (using an updated #1824) vs static method (above) with Example tree: Setup: from gramps.gen.db.utils import open_database
from gramps.gen.lib.eventtype import EventType
db = open_database("Example") Turning into an object (uses old, standard Gramps code; no changes to code base once #1824 is merged):
Using the static method (requires an import):
So, the static method is twice as fast (saves 30 ms over 3,432 events), but at the cost of having to know about a special static method and requiring an import. Personally, I don't think it is worth it, but I support you in whatever direction you want to go. |
@stevenyoungs, what do you want to do to fix the bugs that you found? |
@dsblank I'll hopefully get some time over the coming days to come back to this. |
That sounds fine to me! It is there if one wants to use it. #1824 has been merged, so either of the code examples above will work. |
@dsblank I revised it to an @classmethod and implemented in GrampsType. This way it works for all types, not just EventType |
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.
I left some questions/comments, but it is better than before, and also fixes a bug or two. Thanks!
31512e6
to
6e3e0d5
Compare
This is a bug fix for #1786 (which was an enhancement). Can someone add the bug label please? |
Ready to merge, IMO. |
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.
Only one real issue.
Classmethod get_str is added for performance reasons to avoid creating an object from a dict when only the type is required. __str__ and get_str both rely on __get_str to avoid duplication of logic.
Rebase onto the upstream/master, and use DataDict wrapper.
Uses value["value"] rather than value.value to ensure it works with a plain dict as well as a DataDict
d5ed37c
to
3a4ef56
Compare
@Nick-Hall this is ready for re-review. Thanks. |
Teach GrampsType.set() how to work when value is of
dict
typeThis fixes a bug introduced by PR #1786
To reproduce:
Birth
in the event view