Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/backend.py
Show First 20 Lines • Show All 858 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]: | ||||
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)) | psycopg2.extras.execute_values(cur=cur, sql=query, argslist=primary_keys) | ||||
row = cur.fetchone() | return [OriginVisitStats(**row) for row in cur.fetchall()] | ||||
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 ;) | |||||
if row: | |||||
return OriginVisitStats(**row) | |||||
else: | |||||
return None | |||||
@db_transaction() | @db_transaction() | ||||
Done Inline Actionsoverall, improvment suggestions welcome ;) ardumont: overall, improvment suggestions welcome ;) | |||||
def update_metrics( | def update_metrics( | ||||
self, | self, | ||||
lister_id: Optional[UUID] = None, | lister_id: Optional[UUID] = None, | ||||
timestamp: Optional[datetime.datetime] = None, | timestamp: Optional[datetime.datetime] = None, | ||||
db=None, | db=None, | ||||
cur=None, | cur=None, | ||||
) -> List[SchedulerMetrics]: | ) -> List[SchedulerMetrics]: | ||||
"""Update the performance metrics of this scheduler instance. | """Update the performance metrics of this scheduler instance. | ||||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |
btw