Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/backend.py
Show First 20 Lines • Show All 814 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]: | ) -> List[OriginVisitStats]: | ||||
query = format_query( | if not ids: | ||||
"SELECT {keys} FROM origin_visit_stats WHERE url=%s AND visit_type=%s", | return [] | ||||
OriginVisitStats.select_columns(), | |||||
) | pks = tuple((origin, visit_type) for (origin, visit_type) in ids) | ||||
cur.execute(query, (url, visit_type)) | query = format_query("SELECT {keys} ", OriginVisitStats.select_columns(),) | ||||
row = cur.fetchone() | placeholder_query = ("%s," * len(pks))[:-1] | ||||
vlorentz: btw | |||||
ardumontAuthorUnsubmitted 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 ;) | |||||
query += f"FROM (VALUES {placeholder_query}) as stats(url, visit_type) " | |||||
query += "INNER JOIN origin_visit_stats USING (url, visit_type)" | |||||
ardumontAuthorUnsubmitted Done Inline Actionsoverall, improvment suggestions welcome ;) ardumont: overall, improvment suggestions welcome ;) | |||||
cur.execute(query, pks) | |||||
stats = [] | |||||
for row in cur.fetchall(): | |||||
stats.append(OriginVisitStats(**row)) | |||||
if row: | return stats | ||||
return OriginVisitStats(**row) | |||||
else: | |||||
return None |
btw