#9 Another round of QoL
Closed 4 years ago by frantisekz. Opened 4 years ago by frantisekz.

file modified
+3 -1
@@ -9,5 +9,7 @@ 

  OIDC_REQUIRE_VERIFIED_EMAIL = False

  OIDC_SCOPES = ['openid', 'email', 'profile']

  

- SKIP_CACHE_AGE_CHECK = False # Skip checking cache age in runtime, make sure to set up cron with "runcli.py sync" if set to True

+ # MAX_DB_AGE will be ignored if FORCE_CACHED_DATA, DB cache will be used no matter how old it is

+ # make sure to set up cron with "runcli.py sync" if set to True

+ FORCE_CACHED_DATA = False

  MAX_DB_AGE = 1800 # Max cache age allowed in seconds (30 minutes)

file modified
+3 -1
@@ -49,6 +49,7 @@ 

  

      if current_rev:

          print("Database already initialized and at rev %s - not re-initializing" % current_rev)

+         return True

      else:

          print("Initializing Database")

          db.drop_all()
@@ -57,6 +58,7 @@ 

          print("Initializing alembic version")

  

          al_command.stamp(alembic_cfg, "head")

+         return True

  

  

  def upgrade_db():
@@ -67,7 +69,7 @@ 

  def sync():

      print("Refreshing DB Cache")

      app.config['MAX_DB_AGE'] = 0

-     app.config['SKIP_CACHE_AGE_CHECK'] = False

+     app.config['FORCE_CACHED_DATA'] = False

      db_utils.refresh_data("get_actions", controllers.main.get_actions())

      db_utils.refresh_data("api_v1_landing_page", controllers.main.get_landing_page_data())

      db_utils.refresh_data("api_v1_libkarma",

file modified
+2 -1
@@ -40,13 +40,14 @@ 

      OIDC_REQUIRE_VERIFIED_EMAIL = False

      OIDC_SCOPES = ['openid', 'email', 'profile']

  

-     SKIP_CACHE_AGE_CHECK = False

+     FORCE_CACHED_DATA = False

      MAX_DB_AGE = 1800  # keep data cached for 30 minutes

  

  

  class ProductionConfig(Config):

      PRODUCTION = True

      DEBUG = False

+     FORCE_CACHED_DATA = True

  

  

  class DevelopmentConfig(Config):

file modified
+2 -5
@@ -28,9 +28,9 @@ 

  def is_new_enough(db_time):

      """

      Checks if given db_time is new enough according to MAX_DB_AGE

-     Skips check if SKIP_CACHE_AGE_CHECK is set to True

+     Skips check if FORCE_CACHED_DATA is set to True

      """

-     if app.config['SKIP_CACHE_AGE_CHECK']:

+     if app.config['FORCE_CACHED_DATA']:

          return True

      if not db_time:

          return False
@@ -41,10 +41,7 @@ 

  def refresh_data(provider, data):

      """

      Refreshes given data for given provider in the db

-     Returns immediately when SKIP_CACHE_AGE_CHECK is set

      """

-     if app.config['SKIP_CACHE_AGE_CHECK']:

-         return True

      row = CachedData.query.filter_by(provider=provider).first()

      if row:

          row.time_created = datetime.utcnow()

  • Rename SKIP_CACHE_AGE_CHECK to a more explicit ALWAYS_USE_CACHE
  • set ALWAYS_USE_CACHE to True for Production
  • Auto init db when launching oraculum
  • Don't skip refresh_data(provider, data) on ALWAYS_USE_CACHE

rebased onto 5d1501f

4 years ago

1 new commit added

  • Rename ALWAYS_USE_CACHE to FORCE_CACHED_DATA
4 years ago

Looks like these changes (updated based on my review there) are also part of the PR #10 - this PR should probably be removed?

Yes, can be merged as part of #10 :)

Pull-Request has been closed by frantisekz

4 years ago