Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/db.py
Show First 20 Lines • Show All 470 Lines • ▼ Show 20 Lines | ) -> None: | ||||
f"VALUES ((select id from origin_id), " | f"VALUES ((select id from origin_id), " | ||||
f"{', '.join(['%s']*len(cols))}, %s) " | f"{', '.join(['%s']*len(cols))}, %s) " | ||||
f"ON CONFLICT (origin, visit, date) do nothing", | f"ON CONFLICT (origin, visit, date) do nothing", | ||||
[visit_status.origin] | [visit_status.origin] | ||||
+ [getattr(visit_status, key) for key in cols] | + [getattr(visit_status, key) for key in cols] | ||||
+ [jsonize(visit_status.metadata)], | + [jsonize(visit_status.metadata)], | ||||
) | ) | ||||
origin_visit_upsert_cols = [ | def origin_visit_add_with_id(self, origin_visit: OriginVisit, cur=None) -> None: | ||||
"origin", | """Insert origin visit when id are already set | ||||
"visit", | |||||
"date", | |||||
"type", | |||||
] | |||||
def origin_visit_upsert(self, origin_visit: OriginVisit, cur=None) -> None: | """ | ||||
ov = origin_visit | |||||
assert ov.visit is not None | |||||
# doing an extra query like this is way simpler than trying to join | # doing an extra query like this is way simpler than trying to join | ||||
# the origin id in the query below | # the origin id in the query below | ||||
ov = origin_visit | |||||
origin_id = next(self.origin_id_get_by_url([ov.origin])) | origin_id = next(self.origin_id_get_by_url([ov.origin])) | ||||
ardumont: Funny thing, if i'm calling the method with the "right" `cur`, i got the following error P715… | |||||
ardumontAuthorUnsubmitted Done Inline ActionsD3420 overcomes this by dropping this call altogether... ardumont: D3420 overcomes this by dropping this call altogether... | |||||
origin_visit_cols = ["origin", "visit", "date", "type"] | |||||
Not Done Inline ActionsThis call should be using the cursor argument. olasd: This call should be using the cursor argument. | |||||
cur = self._cursor(cur) | cur = self._cursor(cur) | ||||
Not Done Inline ActionsThis needs to be moved above the self.origin_id_get_by_url call olasd: This needs to be moved above the self.origin_id_get_by_url call | |||||
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 (origin, visit) DO NOTHING""".format( | ||||
UPDATE SET {updates}""".format( | cols=", ".join(origin_visit_cols), | ||||
cols=", ".join(self.origin_visit_upsert_cols), | values=", ".join("%s" for col in origin_visit_cols), | ||||
values=", ".join("%s" for col in self.origin_visit_upsert_cols), | |||||
updates=", ".join( | |||||
"{0}=excluded.{0}".format(col) for col in self.origin_visit_upsert_cols | |||||
), | |||||
) | ) | ||||
cur.execute( | cur.execute( | ||||
query, (origin_id, ov.visit, ov.date, ov.type), | query, (origin_id, ov.visit, ov.date, ov.type), | ||||
) | ) | ||||
origin_visit_get_cols = [ | origin_visit_get_cols = [ | ||||
"origin", | "origin", | ||||
"visit", | "visit", | ||||
▲ Show 20 Lines • Show All 790 Lines • Show Last 20 Lines |
Funny thing, if i'm calling the method with the "right" cur, i got the following error P715
(initial cur is passed from storage as well).
Without calling that method with cur, it's fine.