Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/db.py
Show First 20 Lines • Show All 295 Lines • ▼ Show 20 Lines | revision_add_cols = [ | ||||
'directory', 'message', 'author_fullname', 'author_name', | 'directory', 'message', 'author_fullname', 'author_name', | ||||
'author_email', 'committer_fullname', 'committer_name', | 'author_email', 'committer_fullname', 'committer_name', | ||||
'committer_email', 'metadata', 'synthetic', | 'committer_email', 'metadata', 'synthetic', | ||||
] | ] | ||||
revision_get_cols = revision_add_cols + [ | revision_get_cols = revision_add_cols + [ | ||||
'author_id', 'committer_id', 'parents'] | 'author_id', 'committer_id', 'parents'] | ||||
def origin_visit_add(self, origin, ts, cur=None): | def origin_visit_add(self, origin, ts, type, cur=None): | ||||
"""Add a new origin_visit for origin origin at timestamp ts with | """Add a new origin_visit for origin origin at timestamp ts with | ||||
status 'ongoing'. | status 'ongoing'. | ||||
Args: | Args: | ||||
origin: origin concerned by the visit | origin: origin concerned by the visit | ||||
ts: the date of the visit | ts: the date of the visit | ||||
type: type of loader for the visit | |||||
Returns: | Returns: | ||||
The new visit index step for that origin | The new visit index step for that origin | ||||
""" | """ | ||||
cur = self._cursor(cur) | cur = self._cursor(cur) | ||||
self._cursor(cur).execute('SELECT swh_origin_visit_add(%s, %s)', | self._cursor(cur).execute('SELECT swh_origin_visit_add(%s, %s, %s)', | ||||
(origin, ts)) | (origin, ts, type)) | ||||
return cur.fetchone()[0] | return cur.fetchone()[0] | ||||
def origin_visit_update(self, origin_id, visit_id, updates, cur=None): | def origin_visit_update(self, origin_id, visit_id, updates, cur=None): | ||||
"""Update origin_visit's status.""" | """Update origin_visit's status.""" | ||||
cur = self._cursor(cur) | cur = self._cursor(cur) | ||||
update_cols = [] | update_cols = [] | ||||
values = [] | values = [] | ||||
where = ['origin=%s AND visit=%s'] | where = ['origin=%s AND visit=%s'] | ||||
Show All 14 Lines | def origin_visit_update(self, origin_id, visit_id, updates, cur=None): | ||||
{from} | {from} | ||||
WHERE {where}""".format(**{ | WHERE {where}""".format(**{ | ||||
'update_cols': ', '.join(update_cols), | 'update_cols': ', '.join(update_cols), | ||||
'from': from_, | 'from': from_, | ||||
'where': ' AND '.join(where) | 'where': ' AND '.join(where) | ||||
}) | }) | ||||
cur.execute(query, (*values, *where_values)) | cur.execute(query, (*values, *where_values)) | ||||
def origin_visit_upsert(self, origin, visit, date, status, | def origin_visit_upsert(self, origin, visit, date, type, status, | ||||
metadata, snapshot, cur=None): | metadata, snapshot, cur=None): | ||||
cur = self._cursor(cur) | cur = self._cursor(cur) | ||||
query = """INSERT INTO origin_visit ({cols}) VALUES ({values}) | query = """INSERT INTO origin_visit ({cols}) VALUES ({values}) | ||||
ON CONFLICT ON CONSTRAINT origin_visit_pkey DO | ON CONFLICT ON CONSTRAINT origin_visit_pkey DO | ||||
UPDATE SET {updates}""".format( | UPDATE SET {updates}""".format( | ||||
cols=', '.join(self.origin_visit_get_cols), | cols=', '.join(self.origin_visit_get_cols), | ||||
values=', '.join('%s' for col in self.origin_visit_get_cols), | values=', '.join('%s' for col in self.origin_visit_get_cols), | ||||
updates=', '.join('{0}=excluded.{0}'.format(col) | updates=', '.join('{0}=excluded.{0}'.format(col) | ||||
for col in self.origin_visit_get_cols)) | for col in self.origin_visit_get_cols)) | ||||
cur.execute(query, (origin, visit, date, status, metadata, snapshot)) | cur.execute( | ||||
query, (origin, visit, date, type, status, metadata, snapshot)) | |||||
origin_visit_get_cols = ['origin', 'visit', 'date', 'status', 'metadata', | origin_visit_get_cols = ['origin', 'visit', 'date', 'type', 'status', | ||||
'snapshot'] | 'metadata', 'snapshot'] | ||||
def origin_visit_get_all(self, origin_id, | def origin_visit_get_all(self, origin_id, | ||||
last_visit=None, limit=None, cur=None): | last_visit=None, limit=None, cur=None): | ||||
"""Retrieve all visits for origin with id origin_id. | """Retrieve all visits for origin with id origin_id. | ||||
Args: | Args: | ||||
origin_id: The occurrence's origin | origin_id: The occurrence's origin | ||||
▲ Show 20 Lines • Show All 544 Lines • Show Last 20 Lines |