Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/weko-gridlayout/weko_gridlayout/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ def get_by_url(cls, url):

:return: Single page objects or none.
"""
return db.session.query(cls).filter_by(url=url).one()
return db.session.query(cls).filter_by(url=url).one_or_none()

@classmethod
def get_by_repository_id(cls, repository_id):
Expand Down
19 changes: 11 additions & 8 deletions modules/weko-gridlayout/weko_gridlayout/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,22 +495,25 @@ def _add_url_rule(url_or_urls):
'/<path:path>/<string:current_language>', methods=['GET'])
def get_access_counter_record(repository_id, path, current_language):
"""Get access Top page value."""
cached_data = current_cache.get('access_counter')
if path == "main":
widget_design_setting = WidgetDesignServices.get_widget_design_setting(
repository_id, current_language or get_default_language())
else:
page_id = WidgetDesignPage.get_by_url("/"+path).id
design_page = WidgetDesignPage.get_by_url("/" + path)
if design_page:
page_id = design_page.id
widget_design_setting = WidgetDesignPageServices.get_widget_design_setting(
page_id, current_language or get_default_language())
else:
page_id = "main"
widget_design_setting = WidgetDesignServices.get_widget_design_setting(
repository_id, current_language or get_default_language())

widget_ids = [
str(widget.get("widget_id")) for widget in widget_design_setting.get("widget-settings", {})
if widget.get("type") == WEKO_GRIDLAYOUT_ACCESS_COUNTER_TYPE
]
if len(widget_ids) == 0:
return abort(404)


cached_key = "access_counter_{}".format(page_id)
cached_data = current_cache.get(cached_key)
if not cached_data or set(list(json.loads(cached_data.data).keys())) != set(widget_ids):
result = {}
# need to logic check
Expand Down Expand Up @@ -547,7 +550,7 @@ def get_access_counter_record(repository_id, path, current_language):
if result and len(result) > 0:
cached_data = jsonify(result)
ttl = current_app.config.get('INVENIO_CACHE_TTL', 50)
current_cache.set('access_counter', cached_data, ttl)
current_cache.set(cached_key, cached_data, ttl)

return cached_data

Expand Down
Loading