Beispiel #1
0
 def _buildUserGroupInstances(self, cu):
     self.db.loadSchema()
     if "Latest" in self.db.tables:
         cu.execute("drop table Latest")
     if "Caps" in self.db.tables:
         cu.execute("drop table Caps")
     schema.createAccessMaps(self.db)
     schema.createLatest(self.db, withIndexes=False)
     logMe(2, "creating UserGroupInstancesCache table")
     ugi = accessmap.RoleInstances(self.db)
     ugi.rebuild()
     logMe(3, "creating the LatestCache indexes...")
     schema.createLatest(self.db)
     self.db.analyze("LatestCache")
     return True
Beispiel #2
0
 def _buildUserGroupInstances(self, cu):
     self.db.loadSchema()
     if "Latest" in self.db.tables:
         cu.execute("drop table Latest")
     if "Caps" in self.db.tables:
         cu.execute("drop table Caps")
     schema.createAccessMaps(self.db)
     schema.createLatest(self.db, withIndexes=False)
     logMe(2, "creating the CheckTroveCache table...")
     if not createCheckTroveCache(self.db):
         return False
     logMe(2, "creating UserGroupInstancesCache table")
     ugi = accessmap.RoleInstances(self.db)
     ugi.rebuild()
     logMe(3, "creating the LatestCache indexes...")
     schema.createLatest(self.db)
     self.db.analyze("LatestCache")
     return True
Beispiel #3
0
def rebuildLatest(db, recreate=False):
    cu = db.cursor()
    logMe(2, "Updating the Latest table...")
    if recreate:
        cu.execute("DROP TABLE Latest")
        db.loadSchema()
        schema.createLatest(db)
    else:
        cu.execute("DELETE FROM Latest")
    # As a matter of choice, the Latest table only includes stuff that
    # has the isPresent flag to NORMAL. This means we exclude from
    # computation the missing and hidden troves
    cu.execute("""
    insert into Latest (itemId, branchId, flavorId, versionId, latestType)
    select
        instances.itemid as itemid,
        nodes.branchid as branchid,
        instances.flavorid as flavorid,
        nodes.versionid as versionid,
        %(type)d
    from
    ( select
        i.itemid as itemid,
        n.branchid as branchid,
        i.flavorid as flavorid,
        max(n.finalTimestamp) as finaltimestamp
      from instances as i join nodes as n using(itemId, versionId)
      where i.isPresent = %(present)d
      group by i.itemid, n.branchid, i.flavorid
    ) as tmp
    join nodes using(itemId, branchId, finalTimestamp)
    join instances using(itemId, versionId)
    where instances.flavorid = tmp.flavorid
      and instances.isPresent = %(present)d
    """ % {"type" : versionops.LATEST_TYPE_ANY,
           "present" : instances.INSTANCE_PRESENT_NORMAL, })
    # latest type present excludes the removed troves from computation
    cu.execute("""
    insert into Latest (itemId, branchId, flavorId, versionId, latestType)
    select
        instances.itemid as itemid,
        nodes.branchid as branchid,
        instances.flavorid as flavorid,
        nodes.versionid as versionid,
        %(type)d
    from
    ( select
        i.itemid as itemid,
        n.branchid as branchid,
        i.flavorid as flavorid,
        max(n.finalTimestamp) as finaltimestamp
      from instances as i join nodes as n using(itemId, versionId)
      where i.isPresent = %(present)d
        and i.troveType != %(trove)d
      group by i.itemid, n.branchid, i.flavorid
    ) as tmp
    join nodes using(itemId, branchId, finalTimestamp)
    join instances using(itemId, versionId)
    where instances.flavorid = tmp.flavorid
      and instances.isPresent = %(present)d
      and instances.troveType != %(trove)d
    """ % {"type" : versionops.LATEST_TYPE_PRESENT,
           "present" : instances.INSTANCE_PRESENT_NORMAL,
           "trove" : trove.TROVE_TYPE_REMOVED, })
    # for the LATEST_TYPE_NORMAL we only consider the PRESENT latest
    # entries that are not redirects. Branches that end in redirects
    # shouldn't have an entry in LATEST_TYPE_NORMAL
    cu.execute("""
    insert into Latest (itemId, branchId, flavorId, versionId, latestType)
    select itemId, branchId, flavorId, versionId, %(type)d
    from Latest
    join Instances using(itemId, versionId, flavorId)
    where Latest.latestType = %(latest)d
      and Instances.troveType = %(trove)d
    """ % {"type" : versionops.LATEST_TYPE_NORMAL,
           "latest" : versionops.LATEST_TYPE_PRESENT,
           "trove" : trove.TROVE_TYPE_NORMAL, })
    return True
Beispiel #4
0
def rebuildLatest(db, recreate=False):
    cu = db.cursor()
    logMe(2, "Updating the Latest table...")
    if recreate:
        cu.execute("DROP TABLE Latest")
        db.loadSchema()
        schema.createLatest(db)
    else:
        cu.execute("DELETE FROM Latest")
    # As a matter of choice, the Latest table only includes stuff that
    # has the isPresent flag to NORMAL. This means we exclude from
    # computation the missing and hidden troves
    cu.execute(
        """
    insert into Latest (itemId, branchId, flavorId, versionId, latestType)
    select
        instances.itemid as itemid,
        nodes.branchid as branchid,
        instances.flavorid as flavorid,
        nodes.versionid as versionid,
        %(type)d
    from
    ( select
        i.itemid as itemid,
        n.branchid as branchid,
        i.flavorid as flavorid,
        max(n.finalTimestamp) as finaltimestamp
      from instances as i join nodes as n using(itemId, versionId)
      where i.isPresent = %(present)d
      group by i.itemid, n.branchid, i.flavorid
    ) as tmp
    join nodes using(itemId, branchId, finalTimestamp)
    join instances using(itemId, versionId)
    where instances.flavorid = tmp.flavorid
      and instances.isPresent = %(present)d
    """ % {
            "type": versionops.LATEST_TYPE_ANY,
            "present": instances.INSTANCE_PRESENT_NORMAL,
        })
    # latest type present excludes the removed troves from computation
    cu.execute(
        """
    insert into Latest (itemId, branchId, flavorId, versionId, latestType)
    select
        instances.itemid as itemid,
        nodes.branchid as branchid,
        instances.flavorid as flavorid,
        nodes.versionid as versionid,
        %(type)d
    from
    ( select
        i.itemid as itemid,
        n.branchid as branchid,
        i.flavorid as flavorid,
        max(n.finalTimestamp) as finaltimestamp
      from instances as i join nodes as n using(itemId, versionId)
      where i.isPresent = %(present)d
        and i.troveType != %(trove)d
      group by i.itemid, n.branchid, i.flavorid
    ) as tmp
    join nodes using(itemId, branchId, finalTimestamp)
    join instances using(itemId, versionId)
    where instances.flavorid = tmp.flavorid
      and instances.isPresent = %(present)d
      and instances.troveType != %(trove)d
    """ % {
            "type": versionops.LATEST_TYPE_PRESENT,
            "present": instances.INSTANCE_PRESENT_NORMAL,
            "trove": trove.TROVE_TYPE_REMOVED,
        })
    # for the LATEST_TYPE_NORMAL we only consider the PRESENT latest
    # entries that are not redirects. Branches that end in redirects
    # shouldn't have an entry in LATEST_TYPE_NORMAL
    cu.execute(
        """
    insert into Latest (itemId, branchId, flavorId, versionId, latestType)
    select itemId, branchId, flavorId, versionId, %(type)d
    from Latest
    join Instances using(itemId, versionId, flavorId)
    where Latest.latestType = %(latest)d
      and Instances.troveType = %(trove)d
    """ % {
            "type": versionops.LATEST_TYPE_NORMAL,
            "latest": versionops.LATEST_TYPE_PRESENT,
            "trove": trove.TROVE_TYPE_NORMAL,
        })
    return True