-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/improve operation query speed (#60)
### Description Changes the joins from operation to related models to be eagerly joined. This was to address the performance impact of dynamically evaluating the related fields from the main `operations` query. To avoid making another query to resolve related attributes we fetch the related records through the join eagerly. ### Notes Performance of this query still seems like it could be faster but it is a rather complex operation that reaches into most of the models in the database.
- Loading branch information
Showing
6 changed files
with
56 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
from flask_marshmallow import Marshmallow | ||
from flask_sqlalchemy import SQLAlchemy | ||
from flask_static_digest import FlaskStaticDigest | ||
from flask_marshmallow import Marshmallow | ||
|
||
db = SQLAlchemy() | ||
|
||
class SQLiteAlchemy(SQLAlchemy): | ||
def apply_driver_hacks(self, app, info, options): | ||
options.update({ | ||
'isolation_level': 'AUTOCOMMIT', | ||
}) | ||
super(SQLiteAlchemy, self).apply_driver_hacks(app, info, options) | ||
|
||
|
||
db = SQLiteAlchemy() | ||
flask_static_digest = FlaskStaticDigest() | ||
ma = Marshmallow() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,20 @@ | ||
import logging | ||
from functools import wraps | ||
from timeit import default_timer | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
def str_to_bool(string_value): | ||
return string_value.lower() in ("yes", "true", "t", "1") | ||
return string_value.lower() in ("yes", "true", "t", "1") | ||
|
||
|
||
def timer(f): | ||
@wraps(f) | ||
def wrapper(*args, **kwargs): | ||
start_time = default_timer() | ||
response = f(*args, **kwargs) | ||
total_elapsed_time = default_timer() - start_time | ||
logger.info(f"Elapsed time: {total_elapsed_time}") | ||
return response | ||
|
||
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters