-
Notifications
You must be signed in to change notification settings - Fork 21
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
Remove database connection during query init #3128
Open
greenape
wants to merge
92
commits into
master
Choose a base branch
from
asyncio
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
92 commits
Select commit
Hold shift + click to select a range
ba7f5c3
Preflight checks
greenape 7978db5
Fixup
greenape 0076706
Run preflight in get_query
greenape fd1d05c
Set columns post-init where all are required
greenape 1428e83
Need the class for mro
greenape 370a92c
Fix some typos, and call hooks in a sensible order
greenape aa09330
Limit the default tables
greenape 4adaeac
Pass column names when creating table from query
greenape 3056640
Ensure preflight is called before getting column names in head
greenape 3446e70
Move geom column check to preflight
greenape 4d557d8
Protect all tables, drop events prefix
greenape 1b4b901
Fix not running preflight before store,
greenape a9e0757
Syntax, fix tests
greenape b6c8413
Update test to refelect one less link in dep chain
greenape f4802a8
Disallow None for start/stop
greenape 5a75692
Small fixups
greenape 9e21ef2
Fix error return on preflight fail
greenape 26c964d
Wrap geom table arg in a table
greenape 6e556ac
Update tests
greenape 93e54e1
Update table names in test
greenape 3a9b2ae
Match original table order
greenape 85be37c
Update passed table in docs
greenape d33ec65
Update table order in dependency graph
greenape 0045814
Sort provided tables
greenape b47d344
Update query hashed in approval test
greenape a86895c
Fix fast forwarding state machine multiple times, add missing classes…
greenape f809daa
Match cache half life
greenape 43faa71
Preflight subs table
greenape bc7342e
Fix dependency graph order in test
greenape 8c7bf49
Update fm tests
greenape d97c76f
Fix not checking table arg type and geom table construction,
greenape a4e9693
Handle None table case
greenape 7f464ff
Store zero-score cache classes in db
greenape 07dc063
Fix table name typo
greenape 68b2cc9
Syntax for touch_cache
greenape 9c13057
Syntax for sort
greenape b72b207
Wrap in subquery
greenape adadf5b
Missing bracket
greenape aef870e
Add missing cast
greenape 1bce844
Use subquery for get size of cache
greenape d6d5920
Missed a bracket
greenape 86e6c22
Remove zero cache from internal tables in test helper
greenape 1efdd5e
Centralise list of internal tables in helper
greenape c20f4a9
Don't call the database from init of RandomSystemRows
greenape 3f8ed90
Correct import
greenape 96ca0eb
Update CHANGELOG.md
greenape d9d08e7
Move geotable column checks back into init (no db required)
greenape c3507a4
Update CHANGELOG.md
greenape 4baea78
Handle empty table list
greenape 0c6f125
Add missing arg
greenape 1b78892
Fix columns check
greenape c048210
Clean up table signature a bit
greenape 8c50b3b
Fixups after rebase
greenape 61ed2fd
Fix another rebase change
greenape 5a6bb11
More rebase issues
greenape d4a2e85
Fixup geotable, fast forward even if already fast forwarded
greenape 102dbf5
Finish then write meta
greenape faebea2
Supply columns for Table
greenape f906ed0
Fix missing date preflight error test
greenape e2434bc
Update approval test
greenape 23b2728
Call preflight to raise error
greenape 8f2d3c5
Fix some usages of event. and update exceptions, Table usages
greenape 2584008
lint
greenape 6888c06
Update test_query_object_construction.test_construct_query.approved.txt
greenape 6c1cf3b
Merge branch 'master' into asyncio
greenape 0b5cf0c
Make FlowDBTable abstract
greenape db6c404
Cache protected classes
greenape 95bf78b
Correct doctsring
greenape 8d1eb11
Fix column name typos
greenape 0ce6a55
Remove unused imports in preflight
greenape dbbca00
Check for empty string as a table name
greenape a6bfdd8
Dedupe tables
greenape aece3d9
Simplify hooks iteration
greenape f317937
Remove a couple of unused imports
greenape 0de3df1
Fix dodgy suggestion
greenape 137d886
Lint
greenape ddd660d
Call preflight on the query object
greenape a57e843
Update approval tests
greenape 8a09e6c
Need to actually depend on the nested query to force it to store first
greenape 37de99e
Update table param
greenape 1d77308
Add missing columns arguments
greenape 52c0bdc
Pass up preflight errors, fix error test
greenape 302abc7
Fix typo in example
greenape e1510e0
Log at error level for exception
greenape 267fac5
Add missing mpl headers
greenape 36b6b3e
Merge branch 'asyncio' of github.com:Flowminder/FlowKit into asyncio
greenape fea6c74
Delete flowmachine/tests/test_model.py
greenape 489c94e
Correct test name
greenape 22fd099
Add missing columns arg
greenape 9a60732
Update default schema test
greenape bb04fb8
Types for tables
greenape 127d2e9
Merge branch 'master' into asyncio
greenape File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
from typing import Optional | ||
|
||
from flowmachine.core.flowdb_table import FlowDBTable | ||
|
||
|
||
class EventsTable(FlowDBTable): | ||
def __init__(self, *, name, columns: Optional[list[str]] = None) -> None: | ||
super().__init__(schema="events", name=name, columns=columns) | ||
|
||
|
||
class CallsTable(EventsTable): | ||
all_columns = [ | ||
"id", | ||
"outgoing", | ||
"datetime", | ||
"duration", | ||
"network", | ||
"msisdn", | ||
"msisdn_counterpart", | ||
"location_id", | ||
"imsi", | ||
"imei", | ||
"tac", | ||
"operator_code", | ||
"country_code", | ||
] | ||
Comment on lines
+15
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Refactor duplicate column definitions. The # Create a base class for common columns
class CommonEventsTable(EventsTable):
all_columns = [
"id",
"outgoing",
"datetime",
"network",
"msisdn",
"msisdn_counterpart",
"location_id",
"imsi",
"imei",
"tac",
"operator_code",
"country_code",
]
class CallsTable(CommonEventsTable):
def __init__(self, *, columns=None):
super().__init__(name="calls", columns=columns)
# Similar changes for ForwardsTable and SmsTable Also applies to: 31-44, 51-64 |
||
|
||
def __init__(self, *, columns: Optional[list[str]] = None) -> None: | ||
super().__init__(name="calls", columns=columns) | ||
|
||
|
||
class ForwardsTable(EventsTable): | ||
all_columns = [ | ||
"id", | ||
"outgoing", | ||
"datetime", | ||
"network", | ||
"msisdn", | ||
"msisdn_counterpart", | ||
"location_id", | ||
"imsi", | ||
"imei", | ||
"tac", | ||
"operator_code", | ||
"country_code", | ||
] | ||
|
||
def __init__(self, *, columns: Optional[list[str]] = None) -> None: | ||
super().__init__(name="forwards", columns=columns) | ||
|
||
|
||
class SmsTable(EventsTable): | ||
all_columns = [ | ||
"id", | ||
"outgoing", | ||
"datetime", | ||
"network", | ||
"msisdn", | ||
"msisdn_counterpart", | ||
"location_id", | ||
"imsi", | ||
"imei", | ||
"tac", | ||
"operator_code", | ||
"country_code", | ||
] | ||
|
||
def __init__(self, *, columns: Optional[list[str]] = None) -> None: | ||
super().__init__(name="sms", columns=columns) | ||
|
||
|
||
class MdsTable(EventsTable): | ||
all_columns = [ | ||
"id", | ||
"datetime", | ||
"duration", | ||
"volume_total", | ||
"volume_upload", | ||
"volume_download", | ||
"msisdn", | ||
"location_id", | ||
"imsi", | ||
"imei", | ||
"tac", | ||
"operator_code", | ||
"country_code", | ||
] | ||
|
||
def __init__(self, *, columns: Optional[list[str]] = None) -> None: | ||
super().__init__(name="mds", columns=columns) | ||
|
||
|
||
class TopupsTable(EventsTable): | ||
all_columns = [ | ||
"id", | ||
"datetime", | ||
"type", | ||
"recharge_amount", | ||
"airtime_fee", | ||
"tax_and_fee", | ||
"pre_event_balance", | ||
"post_event_balance", | ||
"msisdn", | ||
"location_id", | ||
"imsi", | ||
"imei", | ||
"tac", | ||
"operator_code", | ||
"country_code", | ||
] | ||
|
||
def __init__(self, *, columns: Optional[list[str]] = None) -> None: | ||
super().__init__(name="topups", columns=columns) | ||
|
||
|
||
events_table_map = dict( | ||
calls=CallsTable, | ||
sms=SmsTable, | ||
mds=MdsTable, | ||
topups=TopupsTable, | ||
forwards=ForwardsTable, | ||
) |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
from abc import ABCMeta | ||
from typing import Optional | ||
|
||
from flowmachine.core.table import Table | ||
|
||
|
||
class FlowDBTable(Table, metaclass=ABCMeta): | ||
""" | ||
Abstract base class for fixed tables that exist in FlowDB. | ||
|
||
Parameters | ||
---------- | ||
name : str | ||
schema : str | ||
columns : list of str | ||
""" | ||
|
||
def __init__(self, *, name: str, schema: str, columns: Optional[list[str]]) -> None: | ||
if columns is None: | ||
columns = self.all_columns | ||
if set(columns).issubset(self.all_columns): | ||
super().__init__(schema=schema, name=name, columns=columns) | ||
else: | ||
raise ValueError( | ||
f"Columns {columns} must be a subset of {self.all_columns}" | ||
) | ||
|
||
@property | ||
def all_columns(self): | ||
raise NotImplementedError | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🛠️ Refactor suggestion
Consider optimizing the cache score calculation performance.
The subquery
(SELECT array_agg(object_class) as classes FROM cache.zero_cache)
will be executed on every cache touch operation. For better performance, consider:Example optimization using a JOIN:
📝 Committable suggestion