This repository has been archived by the owner on Jun 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
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 #256 from editorsnotes/action-api
Improve project serializer and API for getting action histories
- Loading branch information
Showing
11 changed files
with
107 additions
and
71 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
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
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
39 changes: 12 additions & 27 deletions
39
editorsnotes/search/management/commands/rebuild_activity_index.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 |
---|---|---|
@@ -1,41 +1,26 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.db import models | ||
|
||
from reversion.models import Version | ||
from editorsnotes.main.models.auth import LogActivity | ||
|
||
from editorsnotes.main.models.base import Administered | ||
|
||
from ... import activity_index | ||
from ... import get_index | ||
|
||
class Command(BaseCommand): | ||
help = 'Rebuild elasticsearch activity index' | ||
def handle(self, *args, **kwargs): | ||
activity_index = get_index('activity') | ||
|
||
activity_index.delete() | ||
activity_index.create() | ||
|
||
administered_models = list( | ||
m._meta.model_name for m in models.get_models() | ||
if issubclass(m, Administered)) | ||
|
||
qs = Version.objects\ | ||
.select_related('revision__user', | ||
'revision__revisionproject__project', | ||
'content_type')\ | ||
.filter(content_type__model__in=administered_models)\ | ||
.order_by('-revision__date_created') | ||
qs = LogActivity.objects\ | ||
.select_related('project', 'user', 'content_type') | ||
|
||
|
||
self.stdout.write('Indexing {} actions'.format(qs.count())) | ||
ct = qs.count() | ||
self.stdout.write('Indexing {} actions'.format(ct)) | ||
|
||
i = 0 | ||
CHUNK_SIZE = 1000 | ||
|
||
while True: | ||
chunk = qs[i:i + CHUNK_SIZE] | ||
if not chunk: | ||
break | ||
data = (activity_index.data_from_reversion_version(version) | ||
for version in chunk) | ||
activity_index.es.bulk_index(activity_index.name, 'activity', data) | ||
i += CHUNK_SIZE | ||
|
||
for activity in qs: | ||
activity_index.handle_edit(activity, refresh=False) | ||
i += 1 | ||
if (i % 100 == 0): self.stdout.write('{}/{}'.format(i, ct)) |