-
Notifications
You must be signed in to change notification settings - Fork 415
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
Business Logic #1785
base: master
Are you sure you want to change the base?
Business Logic #1785
Conversation
Oh yeah, the low-level code requires a DB upgrade. I put a draft of that code here: https://github.com/gramps-project/gramps/blob/e1cab51a2ab4466cdc09cf856e3365242bb643af/scripts/unpickle.py |
And every place that saves the pickle, we'll have to update that too. (Then some day we can get rid of the pickled blobs completely). |
At a quick glance, I really like this approach. I have made a comment about the JSON format in your other PR. In general discussions about this type of enhancement should be on the gramps-devel mailing list or here on GitHub. Not all of our developers use the Discourse forum. |
Sounds good! |
I think moving business logic into the database layer is a truly terrible idea. It seems to run completely contrary to all the ideas we have developed over many years on modularisation, structured programming and abstraction. The database code should be just about accessing the database. Modularisation is all about making the code maintainable. This (unless I have misunderstood, but commit 645b408 seems to be this) makes the code so much more difficult to maintain. |
Well, Business Logic appears in code everywhere! In views, gramplets of all kinds, and filters/rules. And is replicated in multiple places. I don’t think that is very organized. The second part is just optionally implementing those in a lower level. Honestly, the filters I was looking at hadn’t changed in years (probably never). So, I don’t think there would not be much to maintain once written. Don’t you think the possibility of speeding up gramps is worth exploring? |
I've replied to dsblank's comment on the Discourse forum. |
We already have functions such as Perhaps we could just add some new ones like How much quicker is using SQLite to extract JSON fields over returning the entire JSON for an object and using python to extract the fields? |
I think as long as we can select the data and not have to construct the primary objects, any variation will work.
That's an interesting approach. One caveat: the DBAPI versions may have slightly diferrent syntax for JSON path extraction. But we can adjust like we do in Posgresql vs Sqlite. |
But letting the SQL layer pull out the parts will be as fast as possible I think. |
Here is an interesting version:
|
Oh, this works really well. I'm going to test what the speed difference is between the generic + jsonpath_ng vs dbapi + JSON_EXTRACT. Place your bets. |
I can probably refactor the generic Time to select
db = open_database("Example")
start = time.time()
for handle in db.get_person_handles():
data = extract_data_generic(db, "person", handle, ["$.handle", "$.gramps_id"])
assert data[0] == handle
print("Generic", time.time() - start)
start = time.time()
for handle in db.get_person_handles():
data = extract_data_sql(db, "person", handle, ["$.handle", "$.gramps_id"])
assert data[0] == handle
print("SQL", time.time() - start)
db.close() |
Caching the parser for each json_path in the generic method gives:
|
Since this works so well, and now works on generic database API, the question is: do we want to confine the use to inside BusinessLogic? Or move extract_data() to DbGeneric and use wherever it is useful over the code base? It does seem like we can use extract_data() wherever we want (so move to DbGeneric) but it still makes organizational sense to have a collection of business logic separate from the DB. |
From https://www.sqlite.org/json1.html#jex Regarding Postgresql: not sure if it requires a field type of |
Re compatibility:
|
The version of sqlite3 in Ubuntu Jammy (22.04LTS) is v3.37.2. What versions do we want to support in Gramps? For Gtk and python we support versions that are not EOL at the time of release. However SQLite only supports the latest release. It would probably be unreasonable of us to require the latest release. It would be nice to be able to use the |
Add a Gramps glossary placeholder for JSON ( https://gramps-project.org/wiki/index.php/Gramps_Glossary#J ) so we have a place to link introductory material about the BLOB to JSON change. |
This PR is an example of speeding up Gramps by creating a "Business Logic" layer. The Business Logic layer is composed of functions largely moved out of filters and rules. The BusinessLogic class is designed to be a Mixin for every database class.
Once the code has been moved out of the filter/rule, then specific implementations can be implemented in the low level database class.
I'll discuss more of this in the discussion group: https://gramps.discourse.group/t/business-logic-via-underloads/6211?u=dsblank