forked from City-of-Helsinki/linkedevents
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request City-of-Helsinki#200 from City-of-Helsinki/only-up…
…date-changed-keywords-and-places Expand management command to only update changed event numbers
- Loading branch information
Showing
9 changed files
with
182 additions
and
55 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from django.core.management import BaseCommand, CommandError | ||
from django.db import transaction | ||
|
||
from events.models import Keyword, Place | ||
from events.utils import recache_n_events_in_locations, recache_n_events | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Update keyword and place event numbers" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('model', nargs='?', default=False) | ||
parser.add_argument('--all', | ||
default=False, | ||
action='store_true', | ||
dest='update_all', | ||
help='Recalculate everything from scratch') | ||
|
||
def handle_keywords(self, update_all=False): | ||
if update_all: | ||
keywords = Keyword.objects.all() | ||
else: | ||
keywords = Keyword.objects.filter(n_events_changed=True) | ||
recache_n_events((k.id for k in keywords), all=update_all) | ||
print("Updated %s keyword event numbers." % ('all' if update_all else 'changed')) | ||
print("A total of %s keywords updated." % (str(keywords.count()))) | ||
|
||
def handle_places(self, update_all=False): | ||
if update_all: | ||
places = Place.objects.all() | ||
else: | ||
places = Place.objects.filter(n_events_changed=True) | ||
recache_n_events_in_locations((k.id for k in places), all=update_all) | ||
print("Updated %s place event numbers." % ('all' if update_all else 'changed')) | ||
print("A total of %s places updated." % (str(places.count()))) | ||
|
||
def handle(self, model=None, update_all=False, **kwargs): | ||
if model and model not in ('keyword', 'place'): | ||
raise CommandError("Model %s not found. Valid models are 'keyword' and 'place'." % (model, )) | ||
if not model or model == 'keyword': | ||
self.handle_keywords(update_all=update_all) | ||
if not model or model == 'place': | ||
self.handle_places(update_all=update_all) | ||
|
||
|
32 changes: 32 additions & 0 deletions
32
events/migrations/0037_add_n_events_changed_to_keyword_and_place.py
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,32 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9.11 on 2017-03-15 15:54 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.manager | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('events', '0036_add_n_events_to_place'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelManagers( | ||
name='place', | ||
managers=[ | ||
('geo_objects', django.db.models.manager.Manager()), | ||
], | ||
), | ||
migrations.AddField( | ||
model_name='keyword', | ||
name='n_events_changed', | ||
field=models.BooleanField(db_index=True, default=False), | ||
), | ||
migrations.AddField( | ||
model_name='place', | ||
name='n_events_changed', | ||
field=models.BooleanField(db_index=True, default=False), | ||
), | ||
] |
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
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