diff --git a/data b/data index 04cf639451fc827f89a23eaf60969c061792ea1c..a46a133493ee3ec49e49844a8d0569d2c73f0e1e 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 04cf639451fc827f89a23eaf60969c061792ea1c +Subproject commit a46a133493ee3ec49e49844a8d0569d2c73f0e1e diff --git a/src/flask_covid19/blueprints/app_all/all_model.py b/src/flask_covid19/blueprints/app_all/all_model.py index 2cabd10981dc01cfe848dfa20341b071b8ed3568..d8a816063b0df01a9c2cd20bb0c82fcedb7748ac 100644 --- a/src/flask_covid19/blueprints/app_all/all_model.py +++ b/src/flask_covid19/blueprints/app_all/all_model.py @@ -13,12 +13,8 @@ class BlueprintEntity(db.Model): @classmethod def remove_all(cls): - num_rows_deleted = 0 - try: - num_rows_deleted = db.session.query(cls).delete() - db.session.commit() - except Exception: - db.session.rollback() + num_rows_deleted = db.session.query(cls).delete() + db.session.commit() return num_rows_deleted @classmethod @@ -39,7 +35,7 @@ class BlueprintEntity(db.Model): return db.session.query(cls).paginate(page, per_page=ITEMS_PER_PAGE) @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def find_all(cls): return db.session.query(cls).all() @@ -58,7 +54,7 @@ class BlueprintEntity(db.Model): return db.session.query(cls).filter(cls.id == other_id).one_or_none() @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def set_all_processed_full_update(cls): for o in cls.find_by_not_processed_full_update(): o.set_processed_full_update() @@ -82,12 +78,12 @@ class BlueprintEntity(db.Model): return self @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def find_by_not_processed_update(cls): return db.session.query(cls).filter(not_(cls.processed_update)).all() @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def find_by_not_processed_full_update(cls): return db.session.query(cls).filter(not_(cls.processed_full_update)).all() @@ -128,7 +124,7 @@ class BlueprintDateReported(BlueprintEntity): return self.get_names_for_weekday()[self.day_of_week] @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def get_names_for_weekday(cls): return {1: "Montag", 2: "Dienstag", 3: "Mittwoch", 4: "Donnerstag", 5: "Freitag", 6: "Samstag", 7: "Sonntag"} @@ -137,6 +133,7 @@ class BlueprintDateReported(BlueprintEntity): return self.get_names_for_months()[self.month] @classmethod + @cache.cached(timeout=50) def get_names_for_months(cls): return {1: "Januar", 2: "Februar", 3: "März", 4: "April", 5: "Mai", 6: "Juni", 7: "Juli", 8: "August", 9: "September", 10: "Oktober", 11: "November", 12: "Dezember"} @@ -168,14 +165,14 @@ class BlueprintDateReported(BlueprintEntity): .all() @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def get_joungest_datum(cls): return db.session.query(cls)\ .order_by(cls.datum.desc())\ .first() @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def set_all_processed_update(cls): for o in cls.find_by_not_processed_update(): o.set_processed_update() @@ -183,12 +180,12 @@ class BlueprintDateReported(BlueprintEntity): return None @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def find_all(cls): return db.session.query(cls).order_by(cls.datum.desc()).all() @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def find_all_as_dict(cls): dates_reported = {} for my_date_reported in cls.find_all(): @@ -213,7 +210,7 @@ class BlueprintLocationGroup(BlueprintEntity): location_group = db.Column(db.String(255), nullable=False, unique=True) @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def get_last(cls): return db.session.query(cls).order_by(cls.location_group).all().pop() @@ -239,12 +236,12 @@ class BlueprintLocationGroup(BlueprintEntity): .paginate(page, per_page=ITEMS_PER_PAGE) @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def find_all(cls): return db.session.query(cls).order_by(cls.location_group).all() @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def find_all_as_dict(cls): dates_reported = {} for my_location_group in cls.find_all(): @@ -351,12 +348,12 @@ class BlueprintLocation(BlueprintEntity): .one() @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def find_all(cls): return db.session.query(cls).order_by(cls.location).all() @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def find_all_as_dict(cls): dates_reported = {} for my_location in cls.find_all(): @@ -392,7 +389,7 @@ class BlueprintFactTableTimeSeries(BlueprintEntity): order_by='desc(BlueprintDateReported.datum)') @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def get_date_reported_list(cls): date_reported_list = [] for data in db.session.query(cls).options(subqueryload("date_reported").load_only("datum")): @@ -403,7 +400,7 @@ class BlueprintFactTableTimeSeries(BlueprintEntity): return date_reported_list @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def get_joungest_date_reported(cls): data = cls.get_date_reported_list() if len(data) > 0: @@ -491,7 +488,7 @@ class AllImport(BlueprintEntity): .all() @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def get_datum_list(cls): return db.session.query(cls.datum) \ .order_by(cls.datum.desc()) \ diff --git a/src/flask_covid19/blueprints/data_who/who_model_import.py b/src/flask_covid19/blueprints/data_who/who_model_import.py index d9567acc76272d2042c0e6bee9b84d37bfe90d0e..c143c93e5ce1e1dacaa2812f4a7cc2ffaedec1d9 100644 --- a/src/flask_covid19/blueprints/data_who/who_model_import.py +++ b/src/flask_covid19/blueprints/data_who/who_model_import.py @@ -30,14 +30,14 @@ class WhoImport(AllImport): date_reported = db.Column(db.String(255), nullable=False) @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def get_regions(cls): return db.session.query(cls.who_region)\ .order_by(cls.who_region)\ .distinct().all() @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def get_dates_reported(cls): return db.session.query(cls.date_reported)\ .order_by(cls.date_reported.desc())\ @@ -45,14 +45,14 @@ class WhoImport(AllImport): @classmethod @cache.memoize(50) - def get_for_one_day(cls, day): + def get_for_one_day(cls, day: str): return db.session.query(cls)\ .filter(cls.date_reported == day)\ .order_by(cls.country.asc())\ .all() @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def get_dates_reported_as_string_array(cls): myresultarray = [] myresultset = db.session.query(cls.datum)\ @@ -137,19 +137,19 @@ class WhoImport(AllImport): return new_dates @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def get_new_dates_as_array(cls): # return cls.__get_new_dates_as_array_sql() return cls.__get_new_dates_as_array_orm() @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def countries(cls): bu = Bundle('countries', cls.country_code, cls.country, cls.who_region) return db.session.query(bu).distinct() @classmethod - @cache.memoize(50) + @cache.cached(timeout=50) def get_datum_of_all_who_import(cls): dates_reported = [] bu = Bundle('dates_reported', cls.date_reported)