Skip to content

Commit a8a662f

Browse files
committed
enh: use cached database partly for showing 'my_data' (#5)
1 parent 2776a68 commit a8a662f

4 files changed

Lines changed: 24 additions & 16 deletions

File tree

dcoraid/dbmodel/db_api_cached.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,19 @@ def get_collections(self, refresh=False):
7474
clist += self.ai.get_collections()
7575
return clist
7676

77-
def get_datasets_user_following(self):
77+
def get_datasets_user_following(self) -> DBExtract:
7878
"""Return datasets the user is following"""
7979
# TODO: Use datasets in self._mc
8080
return self.ai.get_datasets_user_following()
8181

82-
def get_datasets_user_owned(self):
82+
def get_datasets_user_owned(self) -> DBExtract:
8383
"""Return datasets the user created"""
8484
own_list = self._mc.datasets_user_owned
8585
ds_list = self._mc.datasets
86-
return [ds for (ds, byuser) in zip(ds_list, own_list) if byuser]
86+
owned = [ds for (ds, byuser) in zip(ds_list, own_list) if byuser]
87+
return DBExtract(owned)
8788

88-
def get_datasets_user_shared(self):
89+
def get_datasets_user_shared(self) -> DBExtract:
8990
"""Return datasets shared with the user"""
9091
# TODO: Use datasets in self._mc
9192
return self.ai.get_datasets_user_shared()

dcoraid/dbmodel/meta_cache.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ def __init__(self,
4747
# a list of dataset IDs as values.
4848
self._registry_org = {}
4949

50-
# List of booleans indicating whether dataset was created by the user
51-
self.datasets_user_owned = []
52-
53-
# Dictionary of databases for persistent storage
50+
#: Dictionary of databases for persistent storage
5451
self._databases = {}
5552

56-
# List of dataset dictionaries
53+
#: List of dataset dictionaries
5754
self.datasets = []
5855

56+
#: List of booleans indicating whether dataset was created by the user
57+
self.datasets_user_owned = []
58+
5959
# Search blob array
6060
self._srt_blobs = None
6161

@@ -125,6 +125,12 @@ def _initialize(self, circle_ids=None):
125125
#: list of datasets, sorted by creation date descending
126126
self.datasets = [datasets[ii] for ii in sort_idx]
127127

128+
#: List of booleans indicating whether dataset was created by the user
129+
self.datasets_user_owned = [
130+
ds_dict["creator_user_id"] == self.user_id
131+
for ds_dict in self.datasets
132+
]
133+
128134
def __enter__(self):
129135
return self
130136

@@ -262,7 +268,7 @@ def _upsert_dataset_insert(self, ds_dict):
262268
# user's dataset list
263269
self.datasets_user_owned.insert(
264270
new_idx,
265-
ds_dict["creator_user_id"] == self.user_id
271+
ds_dict["creator_user_id"] == self.user_id,
266272
)
267273

268274
def _upsert_dataset_update(self, ds_dict):

dcoraid/gui/panel_my_data/widget_my_data.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from PyQt6 import uic, QtCore, QtWidgets
77

88
from ...common import ConnectionTimeoutErrors
9-
from ...dbmodel import APIInterrogator, DBExtract
9+
from ...dbmodel import DBExtract
1010

1111
from ..api import get_ckan_api
1212
from ..main import DCORAid
@@ -34,18 +34,18 @@ def __init__(self, *args, **kwargs):
3434

3535
@QtCore.pyqtSlot()
3636
def on_refresh_private_data(self):
37+
self.find_main_window().check_update_database(force=True)
3738
self.setCursor(QtCore.Qt.CursorShape.WaitCursor)
3839
api = get_ckan_api()
3940
data = DBExtract()
4041
if api.is_available() and api.api_key:
4142
try:
42-
db = APIInterrogator(api=api)
4343
if self.checkBox_user_following.isChecked():
44-
data += db.get_datasets_user_following()
44+
data += self.database.get_datasets_user_following()
4545
if self.checkBox_user_owned.isChecked():
46-
data += db.get_datasets_user_owned()
46+
data += self.database.get_datasets_user_owned()
4747
if self.checkBox_user_shared.isChecked():
48-
data += db.get_datasets_user_shared()
48+
data += self.database.get_datasets_user_shared()
4949
self.user_filter_chain.set_db_extract(data)
5050
except ConnectionTimeoutErrors:
5151
logger.error(tb.format_exc())
@@ -64,5 +64,4 @@ def find_main_window():
6464
return widget
6565

6666
def set_database(self, database):
67-
# TODO: Use this database for searches
6867
self.database = database

tests/test_dbmodel_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ def test_search_dataset_since_time():
196196
# Create a dataset
197197
ds_dict = common.make_dataset_for_download()
198198

199+
time.sleep(.5)
200+
199201
# Run the query again
200202
de1 = db.search_dataset_via_api(since_time=tstart)
201203
# The new dataset should be in the results.

0 commit comments

Comments
 (0)