Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/backend.py
Show First 20 Lines • Show All 831 Lines • ▼ Show 20 Lines | ) -> None: | ||||
page_size=1000, | page_size=1000, | ||||
fetch=False, | fetch=False, | ||||
) | ) | ||||
except CardinalityViolation as e: | except CardinalityViolation as e: | ||||
raise SchedulerException(repr(e)) | raise SchedulerException(repr(e)) | ||||
@db_transaction() | @db_transaction() | ||||
def origin_visit_stats_get( | def origin_visit_stats_get( | ||||
self, url: str, visit_type: str, db=None, cur=None | self, ids: Iterable[Tuple[str, str]], db=None, cur=None | ||||
) -> Optional[OriginVisitStats]: | ) -> Dict[Tuple[str, str], OriginVisitStats]: | ||||
if not ids: | |||||
return {} | |||||
primary_keys = tuple((origin, visit_type) for (origin, visit_type) in ids) | |||||
query = format_query( | query = format_query( | ||||
"SELECT {keys} FROM origin_visit_stats WHERE url=%s AND visit_type=%s", | """ | ||||
SELECT {keys} | |||||
FROM (VALUES %s) as stats(url, visit_type) | |||||
INNER JOIN origin_visit_stats USING (url, visit_type) | |||||
""", | |||||
OriginVisitStats.select_columns(), | OriginVisitStats.select_columns(), | ||||
) | ) | ||||
cur.execute(query, (url, visit_type)) | |||||
row = cur.fetchone() | |||||
if row: | psycopg2.extras.execute_values( | ||||
return OriginVisitStats(**row) | cur=cur, sql=query, argslist=primary_keys, fetch=False, | ||||
vlorentz: btw | |||||
Done Inline Actions"of course", yesterday evening, that would not come to me ¯\_(ツ)_/¯ Thanks ;) ardumont: "of course", yesterday evening, that would not come to me ¯\_(ツ)_/¯
Thanks ;) | |||||
else: | ) | ||||
return None | |||||
Done Inline Actionsoverall, improvment suggestions welcome ;) ardumont: overall, improvment suggestions welcome ;) | |||||
return { | |||||
(row["url"], row["visit_type"]): OriginVisitStats(**row) | |||||
for row in cur.fetchall() | |||||
} |
btw