← Back to team overview

launchpad-reviewers team mailing list archive

Re: [Merge] lp:~wgrant/launchpad/xref-buglinks into lp:launchpad

 


Diff comments:

> 
> === modified file 'lib/lp/answers/model/question.py'
> --- lib/lp/answers/model/question.py	2015-09-28 07:57:17 +0000
> +++ lib/lp/answers/model/question.py	2015-09-29 04:00:42 +0000
> @@ -660,6 +662,20 @@
>          self.status = new_status
>          return tktmsg
>  
> +    @property
> +    def bugs(self):
> +        from lp.bugs.model.bug import Bug
> +        if getFeatureFlag('bugs.xref_buglinks.query'):
> +            bug_ids = [
> +                int(id) for _, id in getUtility(IXRefSet).findFrom(
> +                    (u'question', unicode(self.id)), types=[u'bug'])]

As discussed on IRC, this is easy for arguments, but difficult for results (what happens if the name is really text, but happens to be all digits?). I imagine it'll be handled by an intermediate layer later on.

> +        else:
> +            bug_ids = list(IStore(QuestionBug).find(
> +                QuestionBug,
> +                QuestionBug.question == self).values(QuestionBug.bugID))
> +        return list(sorted(
> +            bulk.load(Bug, bug_ids), key=operator.attrgetter('id')))
> +
>      # IBugLinkTarget implementation
>      def linkBug(self, bug, user=None):
>          """See `IBugLinkTarget`."""
> 
> === modified file 'lib/lp/scripts/garbo.py'
> --- lib/lp/scripts/garbo.py	2015-07-22 07:09:12 +0000
> +++ lib/lp/scripts/garbo.py	2015-09-29 04:00:42 +0000
> @@ -1678,6 +1679,66 @@
>                  transaction.abort()
>  
>  
> +class BugXRefMigrator(TunableLoop):
> +    """Creates an XRef record for each former IBugLink."""
> +
> +    maximum_chunk_size = 5000
> +
> +    def __init__(self, log, abort_time=None):
> +        super(BugXRefMigrator, self).__init__(log, abort_time)
> +        self.start_at = 1
> +        self.store = IMasterStore(Bug)
> +
> +    def findBugs(self):
> +        if not getFeatureFlag('bugs.xref_buglinks.garbo.enabled'):
> +            return EmptyResultSet()
> +        return self.store.find(
> +            Bug, Bug.id >= self.start_at).order_by(Bug.id)
> +
> +    def isDone(self):
> +        return self.findBugs().is_empty()
> +
> +    def __call__(self, chunk_size):
> +        # Grab a chunk of Bug IDs.
> +        # Find all QuestionBugs, SpecificationBugs and BugCves for each
> +        # of those bugs.
> +        # Compose a list of link IDs that should exist.
> +        # Perform a bulk XRef find for all of those.
> +        # Delete any extras, create any missing.

Fixed the comment. It's not necessary.

> +        from lp.blueprints.model.specificationbug import SpecificationBug
> +        from lp.bugs.model.bugcve import BugCve
> +        from lp.bugs.model.cve import Cve
> +        from lp.coop.answersbugs.model import QuestionBug
> +        from lp.services.xref.interfaces import IXRefSet
> +        bug_ids = list(self.findBugs()[:chunk_size].values(Bug.id))
> +        qbs = list(self.store.find(
> +            QuestionBug, QuestionBug.bugID.is_in(bug_ids)))
> +        sbs = list(self.store.find(
> +            SpecificationBug, SpecificationBug.bugID.is_in(bug_ids)))
> +        bcs = list(self.store.find(BugCve, BugCve.bugID.is_in(bug_ids)))
> +        wanted = {(u'bug', unicode(bug_id)): {} for bug_id in bug_ids}
> +        for qb in qbs:
> +            wanted[(u'bug', unicode(qb.bugID))][
> +                (u'question', unicode(qb.questionID))] = {
> +                    'date_created': qb.date_created}
> +        for sb in sbs:
> +            wanted[(u'bug', unicode(sb.bugID))][
> +                (u'specification', unicode(sb.specificationID))] = {}
> +        load_related(Cve, bcs, ['cveID'])
> +        for bc in bcs:
> +            wanted[(u'bug', unicode(bc.bugID))][
> +                (u'cve', unicode(bc.cve.sequence))] = {}
> +        existing = getUtility(IXRefSet).findFromMany(wanted.keys())
> +        needed = {
> +            bug: {
> +                other: meta for other, meta in others.iteritems()
> +                if other not in existing.get(bug, {})}
> +            for bug, others in wanted.iteritems() if others}
> +        getUtility(IXRefSet).create(needed)
> +        self.start_at = bug_ids[-1] + 1
> +        transaction.commit()
> +
> +
>  class FrequentDatabaseGarbageCollector(BaseDatabaseGarbageCollector):
>      """Run every 5 minutes.
>  


-- 
https://code.launchpad.net/~wgrant/launchpad/xref-buglinks/+merge/272591
Your team Launchpad code reviewers is subscribed to branch lp:launchpad.


References