#2764 kojira: faster startup
Merged a year ago by tkopecek. Opened a year ago by tkopecek.
tkopecek/koji issue2612  into  master

file modified
+17 -2
@@ -42,6 +42,14 @@ 

  tag_cache = {}

  

  

+ def prefillTagCache(session):

+     tags = session.listTags()

+     now = time.time()

+     for tag in tags:

+         tag_cache[(tag['id'], None)] = (now, tag)

+         tag_cache[(tag['name'], None)] = (now, tag)

+ 

+ 

  def getTag(session, tag, event=None):

      """A caching version of the hub call"""

      cache = tag_cache
@@ -80,13 +88,18 @@ 

              self._find_expire_time(repodata)

              # TODO use hub data to find the actual expiration time

          self.first_seen = time.time()

-         if self.current:

+         self._taglist = None

+ 

+     @property

+     def taglist(self):

+         if not self._taglist:

              order = self.session.getFullInheritance(self.tag_id, event=self.event_id)

              # order may contain same tag more than once

              tags = {self.tag_id: 1}

              for x in order:

                  tags[x['parent_id']] = 1

-             self.taglist = to_list(tags.keys())

+             self._taglist = to_list(tags.keys())

+         return self._taglist

  

      def _find_expire_time(self, repodata):

          # find all newer repos for same tag and set oldest as expire_ts for our repo
@@ -403,6 +416,8 @@ 

          self.logger.debug("Reading current repo data")

          repodata = self.session.getActiveRepos()

          self.logger.debug("Repo data: %r" % repodata)

+         prefillTagCache(self.session)

+         self.logger.debug("Preloaded %d tags" % len(tag_cache.keys()))

  

          for data in repodata:

              repo_id = data['id']

caching tags in the start + caching property for getting inheritance

Fixes: https://pagure.io/koji/issue/2612

this looks good. The only minor thing is that it seems like the debug line about the tag cache should be in prefillTagCache

It means adding logger as a new option there, but I can do that.

Ah, I guess it's fine as-is then :thumbsup:

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

a year ago

Commit e158b1c fixes this pull-request

Pull-Request has been merged by tkopecek

a year ago

Metadata Update from @jcupova:
- Pull-request tagged with: testing-done

a year ago
Metadata