#NEWLINE# def rebuildLatest( db , recreate = False ) : #NEWLINE# #INDENT# cu = db . cursor ( ) #NEWLINE# logMe ( 2 , 'Updating the Latest table...' ) #NEWLINE# if recreate : #NEWLINE# #INDENT# cu . execute ( 'DROP TABLE Latest' ) #NEWLINE# db . loadSchema ( ) #NEWLINE# schema . createLatest ( db ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cu . execute ( 'DELETE FROM Latest' ) #NEWLINE# #UNINDENT# cu . execute ( ( '\n    insert into Latest (itemId, branchId, flavorId, versionId, latestType)\n    select\n        instances.itemid as itemid,\n        nodes.branchid as branchid,\n        instances.flavorid as flavorid,\n        nodes.versionid as versionid,\n        %(type)d\n    from\n    ( select\n        i.itemid as itemid,\n        n.branchid as branchid,\n        i.flavorid as flavorid,\n        max(n.finalTimestamp) as finaltimestamp\n      from instances as i join nodes as n using(itemId, versionId)\n      where i.isPresent = %(present)d\n      group by i.itemid, n.branchid, i.flavorid\n    ) as tmp\n    join nodes using(itemId, branchId, finalTimestamp)\n    join instances using(itemId, versionId)\n    where instances.flavorid = tmp.flavorid\n      and instances.isPresent = %(present)d\n    ' % { #NEWLINE# #INDENT# 'type' : versionops . LATEST_TYPE_ANY , #NEWLINE# 'present' : instances . INSTANCE_PRESENT_NORMAL , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# cu . execute ( ( '\n    insert into Latest (itemId, branchId, flavorId, versionId, latestType)\n    select\n        instances.itemid as itemid,\n        nodes.branchid as branchid,\n        instances.flavorid as flavorid,\n        nodes.versionid as versionid,\n        %(type)d\n    from\n    ( select\n        i.itemid as itemid,\n        n.branchid as branchid,\n        i.flavorid as flavorid,\n        max(n.finalTimestamp) as finaltimestamp\n      from instances as i join nodes as n using(itemId, versionId)\n      where i.isPresent = %(present)d\n        and i.troveType != %(trove)d\n      group by i.itemid, n.branchid, i.flavorid\n    ) as tmp\n    join nodes using(itemId, branchId, finalTimestamp)\n    join instances using(itemId, versionId)\n    where instances.flavorid = tmp.flavorid\n      and instances.isPresent = %(present)d\n      and instances.troveType != %(trove)d\n    ' % { #NEWLINE# #INDENT# 'type' : versionops . LATEST_TYPE_PRESENT , #NEWLINE# 'present' : instances . INSTANCE_PRESENT_NORMAL , #NEWLINE# 'trove' : trove . TROVE_TYPE_REMOVED , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# cu . execute ( ( '\n    insert into Latest (itemId, branchId, flavorId, versionId, latestType)\n    select itemId, branchId, flavorId, versionId, %(type)d\n    from Latest\n    join Instances using(itemId, versionId, flavorId)\n    where Latest.latestType = %(latest)d\n      and Instances.troveType = %(trove)d\n    ' % { #NEWLINE# #INDENT# 'type' : versionops . LATEST_TYPE_NORMAL , #NEWLINE# 'latest' : versionops . LATEST_TYPE_PRESENT , #NEWLINE# 'trove' : trove . TROVE_TYPE_NORMAL , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# return True