#2336 frontend: cache the queue sizes for one minute
Merged 2 years ago by praiskup. Opened 2 years ago by frostyx.
copr/ frostyx/copr speedup-homepage-2  into  main

@@ -13,6 +13,7 @@ 

  from coprs import helpers

  from coprs import models

  from coprs import exceptions

+ from coprs import cache

  from coprs.exceptions import ObjectNotFound, ActionInProgressException

  from coprs.logic.builds_logic import BuildsLogic

  from coprs.logic.batches_logic import BatchesLogic
@@ -256,6 +257,16 @@ 

          else:

              return []

  

+     @classmethod

+     @cache.memoize(timeout=60)

+     def get_queue_sizes_cached(cls):

+         """

+         The `get_queue_sizes` is IMHO reasonably fast but it is still a major

+         slowdown of rendering the homepage. It is safe to use a cached variant

+         there.

+         """

+         return cls.get_queue_sizes()

+ 

      @staticmethod

      def get_queue_sizes():

          importing = BuildsLogic.get_build_importing_queue(background=False).count()

@@ -102,7 +102,7 @@ 

                                   projects_count=projects_count,

                                   users_count=users_count,

                                   paginator=paginator,

-                                  tasks_info=ComplexLogic.get_queue_sizes(),

+                                  tasks_info=ComplexLogic.get_queue_sizes_cached(),

                                   users_builds=users_builds,

                                   graph=data)

  
@@ -133,7 +133,7 @@ 

                                   coprs=coprs,

                                   pinned=pinned,

                                   paginator=paginator,

-                                  tasks_info=ComplexLogic.get_queue_sizes(),

+                                  tasks_info=ComplexLogic.get_queue_sizes_cached(),

                                   users_builds=users_builds,

                                   graph=data)

  
@@ -178,7 +178,7 @@ 

                              paginator=paginator,

                              fulltext=fulltext,

                              search_string=helpers.format_search_string(params),

-                             tasks_info=ComplexLogic.get_queue_sizes(),

+                             tasks_info=ComplexLogic.get_queue_sizes_cached(),

                              graph=data)

  

  

@@ -26,6 +26,6 @@ 

          upvoted_projects=upvoted_projects,

  

          # Meh this should be done automatically

-         tasks_info=ComplexLogic.get_queue_sizes(),

+         tasks_info=ComplexLogic.get_queue_sizes_cached(),

          graph=BuildsLogic.get_small_graph_data('30min'),

      )

@@ -76,7 +76,7 @@ 

          coprs=coprs,

          pinned=pinned,

          paginator=paginator,

-         tasks_info=ComplexLogic.get_queue_sizes(),

+         tasks_info=ComplexLogic.get_queue_sizes_cached(),

          group=group,

          graph=data

      )

@@ -15,7 +15,7 @@ 

      graph = BuildsLogic.get_small_graph_data('30min')

      return flask.render_template("user_info.html",

                                   user=user,

-                                  tasks_info=ComplexLogic.get_queue_sizes(),

+                                  tasks_info=ComplexLogic.get_queue_sizes_cached(),

                                   graph=graph)

  

  
@@ -68,7 +68,7 @@ 

                                   selected=selected,

                                   coprs=coprs,

                                   form=form,

-                                  tasks_info=ComplexLogic.get_queue_sizes(),

+                                  tasks_info=ComplexLogic.get_queue_sizes_cached(),

                                   graph=graph)

  

  
@@ -110,7 +110,7 @@ 

      OutdatedChrootsLogic.make_review(owner)

      db.session.commit()

      return flask.render_template("repositories.html",

-                                  tasks_info=ComplexLogic.get_queue_sizes(),

+                                  tasks_info=ComplexLogic.get_queue_sizes_cached(),

                                   graph=BuildsLogic.get_small_graph_data('30min'),

                                   owner=owner,

                                   projects=projects)

This reduces the homepage loading time for my local instance from
~0.5s to ~0.05s (for cached results). It also doesn't matter if we
show a minute old numbers. Anyone who needs fresh numbers can still go
to /status.

Build succeeded.

Metadata Update from @frostyx:
- Pull-request tagged with: wip

2 years ago

This needs to be improved a little because I think /status page also uses this now cached variant. I don't want that.

rebased onto 356e2d794ebdf9d185c06dd3e6535e1435387d41

2 years ago

Metadata Update from @frostyx:
- Pull-request untagged with: wip

2 years ago

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

This needs to be improved

ACK, marked WIP then.

Metadata Update from @praiskup:
- Pull-request tagged with: wip

2 years ago

rebased onto 8c62549

2 years ago

Metadata Update from @frostyx:
- Pull-request untagged with: wip

2 years ago

Build succeeded.

Commit 91c1d45 fixes this pull-request

Pull-Request has been merged by praiskup

2 years ago