def load_target(pid, psid, did, dsid, spnid):
    store = IStore(Product)
    p, ps, d, ds, spn = map(
        lambda (cls, id): store.get(cls, id) if id is not None else None,
        zip((Product, ProductSeries, Distribution, DistroSeries,
             SourcePackageName), (pid, psid, did, dsid, spnid)))
    return bug_target_from_key(p, ps, d, ds, spn)
def load_target(pid, psid, did, dsid, spnid):
    store = IStore(Product)
    p, ps, d, ds, spn = map(
        lambda (cls, id): store.get(cls, id) if id is not None else None,
        zip((Product, ProductSeries, Distribution, DistroSeries,
             SourcePackageName),
            (pid, psid, did, dsid, spnid)))
    return bug_target_from_key(p, ps, d, ds, spn)
    def __call__(self, chunk_size):
        """Take a batch of targets and update their BugTasks' name caches.

        See `ITunableLoop`.
        """
        # XXX 2008-03-05 gmb:
        #     We cast chunk_size to an integer to ensure that we're not
        #     trying to slice using floats or anything similarly
        #     foolish. We shouldn't have to do this, but bug #198767
        #     means that we do.
        chunk_size = int(chunk_size)

        start = self.offset
        end = self.offset + chunk_size

        chunk = self.candidates[start:end]

        self.transaction.begin()
        store = IMasterStore(BugTask)

        # Transpose the target rows into lists of object IDs to retrieve.
        ids_to_cache = zip(*(target for (target, names) in chunk))
        for index, cls in enumerate(target_classes):
            # Get all of the objects that we will need into the cache.
            list(store.find(cls, cls.id.is_in(set(ids_to_cache[index]))))

        for target_bits, cached_names in chunk:
            self.offset += 1
            # Resolve the IDs to objects, and get the actual IBugTarget.
            # If the ID is None, don't even try to get an object.
            target_objects = (
                (store.get(cls, id) if id is not None else None)
                for cls, id in zip(target_classes, target_bits))
            target = bug_target_from_key(*target_objects)
            new_name = target.bugtargetdisplayname
            cached_names.discard(new_name)
            # If there are any outdated names cached, update them all in
            # a single query.
            if len(cached_names) > 0:
                self.logger.info(
                    "Updating %r to '%s'." % (tuple(cached_names), new_name))
                self.total_updated += len(cached_names)
                conditions = (
                    col == id for col, id in zip(target_columns, target_bits))
                to_update = store.find(
                    BugTask,
                    BugTask.targetnamecache.is_in(cached_names),
                    *conditions)
                to_update.set(targetnamecache=new_name)

        self.logger.info("Checked %i targets." % len(chunk))

        self.transaction.commit()
    def __call__(self, chunk_size):
        """Take a batch of targets and update their BugTasks' name caches.

        See `ITunableLoop`.
        """
        # XXX 2008-03-05 gmb:
        #     We cast chunk_size to an integer to ensure that we're not
        #     trying to slice using floats or anything similarly
        #     foolish. We shouldn't have to do this, but bug #198767
        #     means that we do.
        chunk_size = int(chunk_size)

        start = self.offset
        end = self.offset + chunk_size

        chunk = self.candidates[start:end]

        self.transaction.begin()
        store = IMasterStore(BugTask)

        # Transpose the target rows into lists of object IDs to retrieve.
        ids_to_cache = zip(*(target for (target, names) in chunk))
        for index, cls in enumerate(target_classes):
            # Get all of the objects that we will need into the cache.
            list(store.find(cls, cls.id.is_in(set(ids_to_cache[index]))))

        for target_bits, cached_names in chunk:
            self.offset += 1
            # Resolve the IDs to objects, and get the actual IBugTarget.
            # If the ID is None, don't even try to get an object.
            target_objects = (
                (store.get(cls, id) if id is not None else None) for cls, id in zip(target_classes, target_bits)
            )
            target = bug_target_from_key(*target_objects)
            new_name = target.bugtargetdisplayname
            cached_names.discard(new_name)
            # If there are any outdated names cached, update them all in
            # a single query.
            if len(cached_names) > 0:
                self.logger.info("Updating %r to '%s'." % (tuple(cached_names), new_name))
                self.total_updated += len(cached_names)
                conditions = (col == id for col, id in zip(target_columns, target_bits))
                to_update = store.find(BugTask, BugTask.targetnamecache.is_in(cached_names), *conditions)
                to_update.set(targetnamecache=new_name)

        self.logger.info("Checked %i targets." % len(chunk))

        self.transaction.commit()