Skip to content

Commit

Permalink
Applying feedback from PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
José Redrejo committed Jul 5, 2022
1 parent 4390a57 commit cf67b53
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
13 changes: 12 additions & 1 deletion kolibri/core/device/migrations/0003_contentcachekey.py
Expand Up @@ -2,21 +2,32 @@
# Generated by Django 1.11.10 on 2018-09-05 17:20
from __future__ import unicode_literals

import sqlite3
import time

from django.db import migrations
from django.db import models
from django.db import transaction
from django.db.utils import OperationalError
from django.db.utils import ProgrammingError


def create_content_cache_key(apps, schema_editor):
from kolibri.core.device.models import ContentCacheKey

ContentCacheKey.update_cache_key()
try:
with transaction.atomic():
ContentCacheKey.update_cache_key()
except (OperationalError, ProgrammingError, sqlite3.OperationalError):
# let's not run this on a database cache
# that might not have been created yet
pass


class Migration(migrations.Migration):

dependencies = [("device", "0002_devicesettings_default_facility")]
atomic = False

operations = [
migrations.CreateModel(
Expand Down
30 changes: 14 additions & 16 deletions kolibri/utils/main.py
Expand Up @@ -25,6 +25,7 @@
from kolibri.core.upgrade import matches_version
from kolibri.core.upgrade import run_upgrades
from kolibri.core.utils.cache import process_cache
from kolibri.deployment.default.cache import CACHES
from kolibri.deployment.default.sqlite_db_names import ADDITIONAL_SQLITE_DATABASES
from kolibri.plugins.utils import autoremove_unavailable_plugins
from kolibri.plugins.utils import check_plugin_config_file_location
Expand Down Expand Up @@ -224,22 +225,19 @@ def _upgrades_before_django_setup(updated, version):


def _post_django_initialization():
if OPTIONS["Cache"]["CACHE_BACKEND"] != "redis":
try:
process_cache.cull()
except SQLite3DatabaseError:
shutil.rmtree(process_cache.directory, ignore_errors=True)
os.mkdir(process_cache.directory)
process_cache._cache = FanoutCache(
process_cache.directory,
settings.CACHES["process_cache"]["SHARDS"],
settings.CACHES["process_cache"]["TIMEOUT"],
**settings.CACHES["process_cache"]["OPTIONS"]
)
except AttributeError:
# DatabaseCache, no actions needed supposing
# kolibri manage createcachetable has been executed previously
pass
if "process_cache" in CACHES: # usually it means not using redis
if "DatabaseCache" not in CACHES["process_cache"]["BACKEND"]:
try:
process_cache.cull()
except SQLite3DatabaseError:
shutil.rmtree(process_cache.directory, ignore_errors=True)
os.mkdir(process_cache.directory)
process_cache._cache = FanoutCache(
process_cache.directory,
settings.CACHES["process_cache"]["SHARDS"],
settings.CACHES["process_cache"]["TIMEOUT"],
**settings.CACHES["process_cache"]["OPTIONS"]
)


def _upgrades_after_django_setup(updated, version):
Expand Down

0 comments on commit cf67b53

Please sign in to comment.