# HG changeset patch # User Marcin Kuzminski # Date 2019-12-19 12:51:29 # Node ID d9dc1c7677f8c57ce535f8d2c1927cb0bcd82049 # Parent 79ad83395ab7d6f07691775beb8e9b3a4eaace4b bookmarks: cache fetching of bookmarks since this is quite expensive query to make with joinedload on repos/repo groups. diff --git a/rhodecode/apps/my_account/views/my_account.py b/rhodecode/apps/my_account/views/my_account.py --- a/rhodecode/apps/my_account/views/my_account.py +++ b/rhodecode/apps/my_account/views/my_account.py @@ -398,12 +398,14 @@ class MyAccountView(BaseAppView, DataGri def my_account_bookmarks(self): c = self.load_default_context() c.active = 'bookmarks' + c.bookmark_items = UserBookmark.get_bookmarks_for_user( + self._rhodecode_db_user.user_id, cache=False) return self._get_template_context(c) def _process_bookmark_entry(self, entry, user_id): position = safe_int(entry.get('position')) cur_position = safe_int(entry.get('cur_position')) - if position is None or cur_position is None: + if position is None: return # check if this is an existing entry diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -5151,13 +5151,19 @@ class UserBookmark(Base, BaseModel): .filter(UserBookmark.position == position).scalar() @classmethod - def get_bookmarks_for_user(cls, user_id): - return cls.query() \ + def get_bookmarks_for_user(cls, user_id, cache=True): + bookmarks = cls.query() \ .filter(UserBookmark.user_id == user_id) \ .options(joinedload(UserBookmark.repository)) \ .options(joinedload(UserBookmark.repository_group)) \ - .order_by(UserBookmark.position.asc()) \ - .all() + .order_by(UserBookmark.position.asc()) + + if cache: + bookmarks = bookmarks.options( + FromCache("sql_cache_short", "get_user_{}_bookmarks".format(user_id)) + ) + + return bookmarks.all() def __unicode__(self): return u'' % (self.position, self.redirect_url)