Skip to content

Commit bd34e96

Browse files
authored
Fix get_data slow when label_type == "name" (#55) (#56)
* Fix get_data slow when label_type == "name" (#55)
1 parent 99010a7 commit bd34e96

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [2.5.2 - 2022-06-02](https://github.com/braincube-io/python-connector/compare/2.5.1...2.5.2)
10+
11+
### FIXED
12+
13+
- #[29](https://github.com/braincube-io/python-connector/issues/29): Fix `{get_data}` very slow when using `{label_type="name"}`
14+
915
## [2.5.1 - 2021-10-25](https://github.com/braincube-io/python-connector/compare/2.5.0...2.5.1)
1016

1117
### FIXED

braincube_connector/memory_base/memory_base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ def get_data(
150150
datasource = data.collect_data(int_var_ids, self, filters)
151151

152152
if label_type == "name":
153-
mapping = {var_id: self.get_variable(var_id).get_name() for var_id in int_var_ids}
153+
mapping = {
154+
int(collected_variable.get_bcid()): collected_variable.get_name()
155+
for collected_variable in self.get_variable_list()
156+
}
154157
datasource = {
155158
mapping[data_key]: data_value for data_key, data_value in datasource.items()
156159
}

tests/test_memory_base/test_memory_base.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,11 @@ def test_get_rule_list(mocker, monkeypatch, mb_obj, mock_request_entity):
157157
)
158158
def test_get_data(mocker, mb_obj, create_mock_var, label_type, dataframe, expected_data):
159159
mocker.patch(
160-
"braincube_connector.memory_base.memory_base.MemoryBase.get_variable",
161-
lambda memory_base_object, bcid: create_mock_var(
162-
bcid=bcid, metadata={"standard": "name_standard_{0}".format(bcid)}
163-
),
160+
"braincube_connector.memory_base.memory_base.MemoryBase.get_variable_list",
161+
return_value=[
162+
create_mock_var(bcid=1, metadata={"standard": "name_standard_1"}),
163+
create_mock_var(bcid=2, metadata={"standard": "name_standard_2"}),
164+
],
164165
)
165166

166167
mocker.patch(

tests_integration/mocks.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@
4949
"status": 200,
5050
"json": {"name": "mb1", "order": "mb1/d101",},
5151
},
52+
{
53+
"method": "GET",
54+
"url": "https://api.test.com/braincube/demo/braincube/mb/1/variables/summary?offset=0&size=150",
55+
"status": 200,
56+
"json": {
57+
"items": [
58+
{"bcId": 101, "tag": "tag_101", "local": "local_101", "standard": "standard_101",},
59+
{"bcId": 102, "tag": "tag_102", "local": "local_102", "standard": "standard_102",},
60+
{"bcId": 103, "tag": "tag_103", "local": "local_103", "standard": "standard_103",},
61+
]
62+
},
63+
},
64+
{
65+
"method": "GET",
66+
"url": "https://api.test.com/braincube/demo/braincube/mb/1/variables/summary?offset=150&size=150",
67+
"status": 200,
68+
"json": {"items": []},
69+
},
5270
{
5371
"method": "POST",
5472
"url": "https://api.test.com/braincube/demo/braindata/mb1/LF",

0 commit comments

Comments
 (0)