diff options
Diffstat (limited to 'scripts/misc.py')
-rw-r--r-- | scripts/misc.py | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/scripts/misc.py b/scripts/misc.py index a2e8ffd..8bad9a1 100644 --- a/scripts/misc.py +++ b/scripts/misc.py @@ -89,7 +89,9 @@ def getTimestampFromContext(context_id): # Finds snapshots that match a host/platform/branch combination and that -# lie within the [sha11, sha12] range. +# lie within the range +# [sha11, sha12] if sha12_id >= 0, or +# [sha11, +inf) if sha12_ is < 0. # Returns a chronologically order n-tuple of 2-tuples: # (sha1, first upload timestamp). def getSnapshots(host_id, platform_id, branch_id, sha11_id, sha12_id): @@ -100,16 +102,26 @@ def getSnapshots(host_id, platform_id, branch_id, sha11_id, sha12_id): " AND branchId = " + str(branch_id) + " AND sha1Id = " + str(sha11_id) + ";")[0][0] - timestamp2 = execQuery( - "SELECT EXTRACT(EPOCH FROM timestamp)::INT FROM context " + - "WHERE hostId = " + str(host_id) + - " AND platformId = " + str(platform_id) + - " AND branchId = " + str(branch_id) + - " AND sha1Id = " + str(sha12_id) + ";")[0][0] + if sha12_id >= 0: + + timestamp2 = execQuery( + "SELECT EXTRACT(EPOCH FROM timestamp)::INT FROM context " + + "WHERE hostId = " + str(host_id) + + " AND platformId = " + str(platform_id) + + " AND branchId = " + str(branch_id) + + " AND sha1Id = " + str(sha12_id) + ";")[0][0] + + # Ensure chronological order: + if timestamp1 > timestamp2: + timestamp1, timestamp2 = timestamp2, timestamp1 + + range_expr = "BETWEEN %d AND %d" % (timestamp1, timestamp2) + + else: + + range_expr = ">= %d" % timestamp1 + - # Ensure chronological order: - if timestamp1 > timestamp2: - timestamp1, timestamp2 = timestamp2, timestamp1 # Each distinct SHA-1 that occurs for this host/platform/branch # combination may occur multiple times with different upload times. @@ -123,9 +135,9 @@ def getSnapshots(host_id, platform_id, branch_id, sha11_id, sha12_id): "WHERE hostId = %d" " AND platformId = %d" " AND branchId = %d" - " AND EXTRACT(EPOCH FROM timestamp)::INT BETWEEN %d AND %d" + " AND EXTRACT(EPOCH FROM timestamp)::INT %s" " ORDER BY timestamp ASC;" - % (host_id, platform_id, branch_id, timestamp1, timestamp2)) + % (host_id, platform_id, branch_id, range_expr)) return tuple(snapshots) |