-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Until now demo users were created in the bootstrap.sh script during the container start when demo mode is activated. This was really slow and resulted in the demo version being offline for up to a minute after a restart. With this update during the container start only the old data will be cleaned up. Demo users are created on the fly by user requests.
- Loading branch information
Showing
21 changed files
with
409 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,4 +65,5 @@ | |
|
||
# demo mode | ||
DEMO_MODE = False | ||
DEMO_MAX_USERS = 10 | ||
DEMO_MODE_RESTART_INTERVAL = 60 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import logging | ||
from pathlib import Path | ||
from shutil import copy | ||
|
||
from django.conf import settings | ||
from django.core.management.base import BaseCommand | ||
from pdf.models import SharedPdf | ||
|
||
logger = logging.getLogger('management') | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Clean up data on start up" | ||
|
||
def handle(self, *args, **kwargs): | ||
clean_up_deleted_shared_pdfs() | ||
|
||
if settings.DEMO_MODE: | ||
clean_demo_db() | ||
|
||
|
||
def clean_up_deleted_shared_pdfs(): | ||
"""Delete shared PDFs with a deletion date in the past.""" | ||
|
||
logger.info('Cleaning up shared PDFs with a deletion date in the past.') | ||
|
||
shared_pdfs = SharedPdf.objects.all() | ||
|
||
for shared_pdf in shared_pdfs: | ||
if shared_pdf.deleted: | ||
shared_pdf.delete() | ||
|
||
|
||
def clean_demo_db( | ||
db_path: Path = settings.BASE_DIR / 'db' / 'db.sqlite3', | ||
after_migration_db_path: Path = settings.BASE_DIR / 'db' / 'migrated.sqlite3', | ||
): | ||
"""Clean the database for the demo mode. In this state the db will have applied migrations but no users or pdfs.""" | ||
|
||
logger.info('Cleaning up the demo database.') | ||
|
||
# If the after_migration_db_path is not present, then the container is started for the first time. | ||
# This means only the migrations were applied until now, so we want preserve this state. | ||
if not after_migration_db_path.exists(): | ||
copy(db_path, after_migration_db_path) | ||
# otherwise replace the migrations db. | ||
else: | ||
db_path.unlink() | ||
copy(after_migration_db_path, db_path) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.