Skip to content

Commit

Permalink
style(tags-db): correct typing in StudyMetadataRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent-laporte-pro committed Feb 7, 2024
1 parent aaaa37b commit de3f20f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion antarest/study/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions antarest/study/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand All @@ -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.
Expand Down
11 changes: 3 additions & 8 deletions antarest/study/storage/auto_archive_service.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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__)
Expand All @@ -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
Expand Down

0 comments on commit de3f20f

Please sign in to comment.