From de3f20f2b2bd315b7ced597a3e8f98a06f3e0d59 Mon Sep 17 00:00:00 2001 From: Laurent LAPORTE Date: Thu, 8 Feb 2024 00:22:27 +0100 Subject: [PATCH] style(tags-db): correct typing in `StudyMetadataRepository` --- antarest/study/model.py | 2 +- antarest/study/repository.py | 10 +++++----- antarest/study/storage/auto_archive_service.py | 11 +++-------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/antarest/study/model.py b/antarest/study/model.py index a8510f3494..fe10b4f211 100644 --- a/antarest/study/model.py +++ b/antarest/study/model.py @@ -32,7 +32,7 @@ DEFAULT_WORKSPACE_NAME = "default" -STUDY_REFERENCE_TEMPLATES: t.Dict[str, str] = { +STUDY_REFERENCE_TEMPLATES: t.Mapping[str, str] = { "600": "empty_study_613.zip", "610": "empty_study_613.zip", "640": "empty_study_613.zip", diff --git a/antarest/study/repository.py b/antarest/study/repository.py index 62b7904a28..3aa6e60681 100644 --- a/antarest/study/repository.py +++ b/antarest/study/repository.py @@ -182,7 +182,7 @@ def get_all( study_filter: StudyFilter = StudyFilter(), sort_by: t.Optional[StudySortBy] = None, pagination: StudyPagination = StudyPagination(), - ) -> t.List[Study]: + ) -> t.Sequence[Study]: """ Retrieve studies based on specified filters, sorting, and pagination. @@ -259,17 +259,17 @@ def get_all( if pagination.page_nb or pagination.page_size: q = q.offset(pagination.page_nb * pagination.page_size).limit(pagination.page_size) - studies: t.List[Study] = q.all() + studies: t.Sequence[Study] = q.all() return studies - def get_all_raw(self, exists: t.Optional[bool] = None) -> t.List[RawStudy]: + def get_all_raw(self, exists: t.Optional[bool] = None) -> t.Sequence[RawStudy]: query = self.session.query(RawStudy) if exists is not None: if exists: query = query.filter(RawStudy.missing.is_(None)) else: query = query.filter(not_(RawStudy.missing.is_(None))) - studies: t.List[RawStudy] = query.all() + studies: t.Sequence[RawStudy] = query.all() return studies def delete(self, id: str) -> None: @@ -278,7 +278,7 @@ def delete(self, id: str) -> None: session.delete(u) session.commit() - def update_tags(self, study: Study, new_tags: t.List[str]) -> None: + def update_tags(self, study: Study, new_tags: t.Sequence[str]) -> None: """ Updates the tags associated with a given study in the database, replacing existing tags with new ones. diff --git a/antarest/study/storage/auto_archive_service.py b/antarest/study/storage/auto_archive_service.py index b2ae1fae63..911b715f2d 100644 --- a/antarest/study/storage/auto_archive_service.py +++ b/antarest/study/storage/auto_archive_service.py @@ -1,7 +1,7 @@ import datetime import logging import time -from typing import List, Tuple +import typing as t from antarest.core.config import Config from antarest.core.exceptions import TaskAlreadyRunning @@ -12,7 +12,6 @@ from antarest.study.model import RawStudy, Study from antarest.study.repository import StudyFilter from antarest.study.service import StudyService -from antarest.study.storage.utils import is_managed from antarest.study.storage.variantstudy.model.dbmodel import VariantStudy logger = logging.getLogger(__name__) @@ -29,12 +28,8 @@ def __init__(self, study_service: StudyService, config: Config): def _try_archive_studies(self) -> None: old_date = datetime.datetime.utcnow() - datetime.timedelta(days=self.config.storage.auto_archive_threshold_days) with db(): - studies: List[Study] = self.study_service.repository.get_all( - study_filter=StudyFilter( - managed=True, - ) - ) - # list of study id and boolean indicating if it's a raw study (True) or a variant (False) + studies: t.Sequence[Study] = self.study_service.repository.get_all(study_filter=StudyFilter(managed=True)) + # list of study IDs and boolean indicating if it's a raw study (True) or a variant (False) study_ids_to_archive = [ (study.id, isinstance(study, RawStudy)) for study in studies