Commit 2c731b9e authored by 20after4's avatar 20after4
Browse files

Make PHIDRef hashable.

Change-Id: I1c1d5966d66fe2b8cd7900b4e7b9c81abe853587
parent 17b1d7a2
......@@ -379,14 +379,43 @@ def main(project, mock, db, dump, table, cache_columns):
CREATE TABLE IF NOT EXISTS column_metrics (trnsid, ts, project phid, column phid, task, type, value);
CREATE TABLE IF NOT EXISTS columns({column_names});
CREATE INDEX IF NOT EXISTS ts_column_value on column_metrics(column, task, ts, value);
CREATE UNIQUE INDEX IF NOT EXISTS trnsid on column_metrics(ts, column, task, value);
CREATE TABLE IF NOT EXISTS task_metrics(task, metric phid, next_metric phid, ts, ts2, duration);
CREATE UNIQUE INDEX IF NOT EXISTS task_metric ON task_metrics(task, metric);
CREATE TABLE IF NOT EXISTS events(ts, task, project phid, user phid, event, old, new);
CREATE UNIQUE INDEX IF NOT EXISTS events_pk on events(ts, task, event);
view_column_metrics AS
c.ts AS ts, AS column_name,
sum(c.value) OVER w AS task_count,
printf('T%u',c.task) AS task,
c.project AS project_phid,
c.column AS column_phid,
" "
) FILTER(WHERE c.value > 0) OVER w AS tasks
FROM column_metrics c, phobjects p
c.type = 'columns'
AND c.column=p.phid
WINDOW w AS ( PARTITION BY c.column ORDER BY c.ts, -c.value)
c.column, c.ts;
......@@ -76,7 +76,9 @@ class Status(Enum):
return self.value
def isPHID(value: Union[str, PHID]) -> bool:
def isPHID(value) -> bool:
if isinstance(value, PHIDRef):
return True
if not isinstance(value, (PHID, str)):
return False
return value.startswith("PHID-")
......@@ -352,10 +354,17 @@ class PHIDRef(object):
def __eq__(self, other) -> bool:
return (
other is self.object
or (isinstance(other, PHIDRef) and other.object is self.object)
or (isinstance(other, str) and isPHID(other) and other == self.toPHID)
or (
isinstance(other, PHIDRef)
and other.toPHID == self.toPHID
and other.fromPHID == self.fromPHID
or (isPHID(other) and other == self.toPHID)
def __hash__(self):
return hash((self.toPHID, self.fromPHID))
def __conform__(self, protocol):
if protocol is sqlite3.PrepareProtocol:
return self.toPHID
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment