Show More
@@ -1,19 +1,27 b'' | |||||
|
1 | from importlib import import_module | |||
|
2 | ||||
1 | from django.core.management import BaseCommand |
|
3 | from django.core.management import BaseCommand | |
2 | from django.db import transaction |
|
4 | from django.db import transaction | |
3 |
from django. |
|
5 | from django.conf import settings | |
4 |
|
6 | |||
5 |
from boards.models import |
|
7 | from boards.models.user import UserSettings | |
6 |
|
8 | |||
7 |
|
9 | |||
|
10 | SessionStore = import_module(settings.SESSION_ENGINE).SessionStore | |||
|
11 | ||||
8 | __author__ = 'neko259' |
|
12 | __author__ = 'neko259' | |
9 |
|
13 | |||
10 |
|
14 | |||
11 | class Command(BaseCommand): |
|
15 | class Command(BaseCommand): | |
12 |
help = 'Remove |
|
16 | help = 'Remove user settings that do not have their sessions.' | |
13 |
|
17 | |||
14 | @transaction.atomic |
|
18 | @transaction.atomic | |
15 | def handle(self, *args, **options): |
|
19 | def handle(self, *args, **options): | |
16 | empty = Tag.objects.annotate(num_threads=Count('thread_tags'))\ |
|
20 | ||
17 | .filter(num_threads=0).order_by('-required', 'name') |
|
21 | count = 0 | |
18 | print('Removing {} empty tags'.format(empty.count())) |
|
22 | for setting in UserSettings.objects.all(): | |
19 | empty.delete() |
|
23 | session = SessionStore(session_key=setting.session_key) | |
|
24 | if session.is_empty(): | |||
|
25 | setting.delete() | |||
|
26 | count += 1 | |||
|
27 | print('Removed {} empty setting objects.'.format(count)) |
@@ -9,7 +9,7 b' from boards.models import Tag' | |||||
9 |
|
9 | |||
10 |
|
10 | |||
11 | class Command(BaseCommand): |
|
11 | class Command(BaseCommand): | |
12 |
help = 'Remove |
|
12 | help = 'Remove tags that have no threads' | |
13 |
|
13 | |||
14 | @transaction.atomic |
|
14 | @transaction.atomic | |
15 | def handle(self, *args, **options): |
|
15 | def handle(self, *args, **options): |
General Comments 0
You need to be logged in to leave comments.
Login now