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):
con.executescript(
f"""
--sql
CREATE TABLE IF NOT EXISTS column_metrics (trnsid, ts, project phid, column phid, task, type, value);
--sql
CREATE TABLE IF NOT EXISTS columns({column_names});
--sql
CREATE INDEX IF NOT EXISTS ts_column_value on column_metrics(column, task, ts, value);
--sql
CREATE UNIQUE INDEX IF NOT EXISTS trnsid on column_metrics(ts, column, task, value);
--sql
CREATE TABLE IF NOT EXISTS task_metrics(task, metric phid, next_metric phid, ts, ts2, duration);
--sql
CREATE UNIQUE INDEX IF NOT EXISTS task_metric ON task_metrics(task, metric);
--sql
CREATE TABLE IF NOT EXISTS events(ts, task, project phid, user phid, event, old, new);
--sql
CREATE UNIQUE INDEX IF NOT EXISTS events_pk on events(ts, task, event);
--sql
CREATE VIEW IF NOT EXISTS
view_column_metrics AS
SELECT
c.ts AS ts,
p.name 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,
group_concat(
printf('T%u',c.task),
" "
) FILTER(WHERE c.value > 0) OVER w AS tasks
FROM column_metrics c, phobjects p
WHERE
c.type = 'columns'
AND c.column=p.phid
WINDOW w AS ( PARTITION BY c.column ORDER BY c.ts, -c.value)
ORDER BY
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