forked from oppia/oppia
-
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.
Fix oppia#2553: Change the "index all explorations" job in the admin …
…dashb… (oppia#3831) * Fix oppia#2553: Change the "index all explorations" job in the admin dashboard to an "index all activities" job * Address review comments * Address review comments * Update docstring to correct parameter name
- Loading branch information
Showing
18 changed files
with
801 additions
and
589 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# coding: utf-8 | ||
# | ||
# Copyright 2017 The Oppia Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS-IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""One-off jobs for activities.""" | ||
|
||
from core import jobs | ||
from core.domain import search_services | ||
from core.platform import models | ||
|
||
(exp_models, collection_models,) = models.Registry.import_models([ | ||
models.NAMES.exploration, models.NAMES.collection]) | ||
|
||
|
||
class IndexAllActivitiesJobManager(jobs.BaseMapReduceOneOffJobManager): | ||
"""Job that indexes all explorations and collections and compute their | ||
ranks. | ||
""" | ||
|
||
@classmethod | ||
def entity_classes_to_map_over(cls): | ||
return [exp_models.ExpSummaryModel, | ||
collection_models.CollectionSummaryModel] | ||
|
||
@staticmethod | ||
def map(item): | ||
if not item.deleted: | ||
if isinstance(item, exp_models.ExpSummaryModel): | ||
search_services.index_exploration_summaries([item]) | ||
else: | ||
search_services.index_collection_summaries([item]) | ||
|
||
@staticmethod | ||
def reduce(key, values): | ||
pass |
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,91 @@ | ||
# coding: utf-8 | ||
# | ||
# Copyright 2017 The Oppia Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS-IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from core.domain import activity_jobs_one_off | ||
from core.domain import collection_services | ||
from core.domain import collection_domain | ||
from core.domain import exp_domain | ||
from core.domain import exp_services | ||
from core.domain import rights_manager | ||
from core.domain import search_services | ||
from core.domain import user_services | ||
from core.platform import models | ||
from core.platform.taskqueue import gae_taskqueue_services as taskqueue_services | ||
from core.tests import test_utils | ||
|
||
gae_search_services = models.Registry.import_search_services() | ||
|
||
class OneOffReindexActivitiesJobTest(test_utils.GenericTestBase): | ||
|
||
def setUp(self): | ||
super(OneOffReindexActivitiesJobTest, self).setUp() | ||
|
||
self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME) | ||
self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL) | ||
self.owner = user_services.UserActionsInfo(self.owner_id) | ||
|
||
explorations = [exp_domain.Exploration.create_default_exploration( | ||
'%s' % i, | ||
title='title %d' % i, | ||
category='category%d' % i | ||
) for i in xrange(3)] | ||
|
||
for exp in explorations: | ||
exp_services.save_new_exploration(self.owner_id, exp) | ||
rights_manager.publish_exploration(self.owner, exp.id) | ||
|
||
collections = [collection_domain.Collection.create_default_collection( | ||
'%s' % i, | ||
title='title %d' % i, | ||
category='category%d' % i | ||
) for i in xrange(3, 6)] | ||
|
||
for collection in collections: | ||
collection_services.save_new_collection(self.owner_id, collection) | ||
rights_manager.publish_collection(self.owner, collection.id) | ||
|
||
self.process_and_flush_pending_tasks() | ||
|
||
def test_standard_operation(self): | ||
job_id = ( | ||
activity_jobs_one_off.IndexAllActivitiesJobManager.create_new()) | ||
activity_jobs_one_off.IndexAllActivitiesJobManager.enqueue(job_id) | ||
|
||
self.assertEqual( | ||
self.count_jobs_in_taskqueue( | ||
taskqueue_services.QUEUE_NAME_ONE_OFF_JOBS), 1) | ||
|
||
indexed_docs = [] | ||
|
||
def add_docs_mock(docs, index): | ||
indexed_docs.extend(docs) | ||
self.assertIn(index, (search_services.SEARCH_INDEX_EXPLORATIONS, | ||
search_services.SEARCH_INDEX_COLLECTIONS)) | ||
|
||
add_docs_swap = self.swap( | ||
gae_search_services, 'add_documents_to_index', add_docs_mock) | ||
|
||
with add_docs_swap: | ||
self.process_and_flush_pending_tasks() | ||
|
||
ids = [doc['id'] for doc in indexed_docs] | ||
titles = [doc['title'] for doc in indexed_docs] | ||
categories = [doc['category'] for doc in indexed_docs] | ||
|
||
for index in xrange(5): | ||
self.assertIn("%s" % index, ids) | ||
self.assertIn('title %d' % index, titles) | ||
self.assertIn('category%d' % index, categories) |
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
Oops, something went wrong.