Skip to content

Commit c0ce77c

Browse files
Merge pull request #113 from jverswijver/update_dynamic_api
Update dynamic api generation to make it more performant
2 parents 340b8d8 + 65c70f9 commit c0ce77c

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) convention.
44

5+
## [0.2.2] - 2021-11-10
6+
### Fixed
7+
- Optimize dynamic api virtual modules.
8+
59
## [0.2.1] - 2021-11-08
610
### Fixed
711
- Error with retrieving the module's installation root path.
@@ -80,6 +84,7 @@ Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and
8084
- Support for DataJoint attribute types: `varchar`, `int`, `float`, `datetime`, `date`, `time`, `decimal`, `uuid`.
8185
- Check dependency utility to determine child table references.
8286

87+
[0.2.2]: https://github.com/datajoint/pharus/compare/0.2.1...0.2.2
8388
[0.2.1]: https://github.com/datajoint/pharus/compare/0.2.0...0.2.1
8489
[0.2.0]: https://github.com/datajoint/pharus/compare/0.1.0...0.2.0
8590
[0.1.0]: https://github.com/datajoint/pharus/compare/0.1.0b2...0.1.0

pharus/dynamic_api_gen.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def populate_api():
1212
from flask import request
1313
from json import loads
1414
from base64 import b64decode
15+
import inspect
1516
"""
1617
route_template = """
1718
@@ -24,9 +25,9 @@ def {method_name}(jwt_payload: dict) -> dict:
2425
if request.method in {{'GET'}}:
2526
try:
2627
djconn = _DJConnector._set_datajoint_config(jwt_payload)
27-
vm_dict = {{s: dj.VirtualModule(s, s, connection=djconn)
28-
for s in dj.list_schemas()}}
29-
query, fetch_args = dj_query(vm_dict)
28+
vm_list = [dj.VirtualModule(s, s, connection=djconn)
29+
for s in inspect.getfullargspec(dj_query).args]
30+
query, fetch_args = dj_query(*vm_list)
3031
query = query & restriction()
3132
record_header, table_tuples, total_count = _DJConnector._fetch_records(
3233
query=query,
@@ -49,9 +50,9 @@ def {method_name}_attributes(jwt_payload: dict) -> dict:
4950
if request.method in {{'GET'}}:
5051
try:
5152
djconn = _DJConnector._set_datajoint_config(jwt_payload)
52-
vm_dict = {{s: dj.VirtualModule(s, s, connection=djconn)
53-
for s in dj.list_schemas()}}
54-
query, fetch_args = dj_query(vm_dict)
53+
vm_list = [dj.VirtualModule(s, s, connection=djconn)
54+
for s in inspect.getfullargspec(dj_query).args]
55+
query, fetch_args = dj_query(*vm_list)
5556
attributes_meta = _DJConnector._get_attributes(query)
5657
5758
return dict(attributeHeaders=attributes_meta['attribute_headers'],

pharus/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"""Package metadata."""
2-
__version__ = '0.2.1'
2+
__version__ = '0.2.2'

tests/init/test_dynamic_api_spec.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ SciViz: # top level tab
2323
def restriction(**kwargs):
2424
return dict(**kwargs)
2525
dj_query: >
26-
def dj_query(vms):
27-
TableA, TableB = (vms['test_group1_simple'].TableA, vms['test_group1_simple'].TableB)
26+
def dj_query(test_group1_simple):
27+
TableA, TableB = (test_group1_simple.TableA, test_group1_simple.TableB)
2828
return TableA * TableB, dict(order_by='b_number')
2929
grid2:
3030
components:
@@ -37,8 +37,8 @@ SciViz: # top level tab
3737
def restriction(**kwargs):
3838
return dict(**kwargs)
3939
dj_query: >
40-
def dj_query(vms):
41-
TableA, TableB = (vms['test_group1_simple'].TableA, vms['test_group1_simple'].TableB)
40+
def dj_query(test_group1_simple):
41+
TableA, TableB = (test_group1_simple.TableA, test_group1_simple.TableB)
4242
return TableA * TableB, dict(order_by='b_number')
4343
4444
page1:
@@ -63,8 +63,8 @@ SciViz: # top level tab
6363
def restriction(**kwargs):
6464
return dict(**kwargs)
6565
dj_query: >
66-
def dj_query(vms):
67-
TableA, TableB = (vms['test_group1_simple'].TableA, vms['test_group1_simple'].TableB)
66+
def dj_query(test_group1_simple):
67+
TableA, TableB = (test_group1_simple.TableA, test_group1_simple.TableB)
6868
return TableA * TableB, dict(order_by='b_number')
6969
component2:
7070
route: /query4
@@ -75,8 +75,8 @@ SciViz: # top level tab
7575
def restriction(**kwargs):
7676
return dict(**kwargs)
7777
dj_query: >
78-
def dj_query(vms):
79-
TableA, TableB = (vms['test_group1_simple'].TableA, vms['test_group1_simple'].TableB)
78+
def dj_query(test_group1_simple):
79+
TableA, TableB = (test_group1_simple.TableA, test_group1_simple.TableB)
8080
return TableA * TableB, dict(order_by='b_number')
8181
diff_checker: >
8282
def diff_checker(**args):
@@ -90,8 +90,8 @@ SciViz: # top level tab
9090
def restriction(**kwargs):
9191
return dict(a_id=0, **kwargs)
9292
dj_query: >
93-
def dj_query(vms):
94-
TableA, TableB = (vms['test_group1_simple'].TableA, vms['test_group1_simple'].TableB)
93+
def dj_query(test_group1_simple):
94+
TableA, TableB = (test_group1_simple.TableA, test_group1_simple.TableB)
9595
return TableA * TableB, dict(order_by='b_number')
9696
diff_checker: >
9797
def diff_checker(**args):

0 commit comments

Comments
 (0)