~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python2.4

# Copyright 2005 Canonical Ltd.  All rights reserved.

# This script updates the cached source package information in the system.
# We use this for fast source package searching (as opposed to joining
# through gazillions of publishing tables).

import _pythonpath

from zope.component import getUtility

from canonical.config import config
from canonical.launchpad.interfaces import IDistributionSet
from canonical.launchpad.scripts.base import LaunchpadScript
from canonical.lp import READ_COMMITTED_ISOLATION


class PackageCacheUpdater(LaunchpadScript):
    def updateDistroReleaseCache(self, distrorelease):
        self.logger.info('%s starting' % distrorelease.name)
        distrorelease.updatePackageCount()
        self.txn.commit()
        distrorelease.removeOldCacheItems(log=self.logger)
        self.txn.commit()
        distrorelease.updateCompletePackageCache(
            ztm=self.txn, log=self.logger)
        self.txn.commit()
        for arch in distrorelease.architectures:
            arch.updatePackageCount()
            self.txn.commit()

    def main(self):
        self.txn.set_isolation_level(READ_COMMITTED_ISOLATION)
        self.logger.debug('Starting the sp cache update')
        # Do the cache update
        distroset = getUtility(IDistributionSet)
        for distro in distroset:
            for distrorelease in distro.releases:
                self.updateDistroReleaseCache(distrorelease)
            distro.removeOldCacheItems(log=self.logger)
            self.txn.commit()
            distro.updateCompleteSourcePackageCache(ztm=self.txn,
                                                    log=self.logger)
            self.txn.commit()
            self.logger.info('%s done' % distro.name)
        self.logger.debug('Finished the sp cache update')

if __name__ == '__main__':
    script = PackageCacheUpdater('spcache', dbuser=config.statistician.dbuser)
    script.lock_and_run()