def test_get_thread_summaries_load_test(self): # The speed of fetching the summaries of 100 threads having 5 messages # should be less than 1.7 second. In reality, the time taken to fetch # all the summaries is less than 0.2s. However since it seems to take # longer on Travis, the constant has been set to 1.7s. # Create 100 threads. for _ in python_utils.RANGE(100): feedback_services.create_thread( feconf.ENTITY_TYPE_EXPLORATION, self.EXP_ID_1, self.user_id, self.EXPECTED_THREAD_DICT['subject'], 'not used here') threadlist = feedback_services.get_all_threads( feconf.ENTITY_TYPE_EXPLORATION, self.EXP_ID_1, False) thread_ids = [] for thread in threadlist: thread_ids.append(thread.id) # Create 5 messages in each thread. for _ in python_utils.RANGE(5): feedback_services.create_message(thread.id, self.user_id, None, None, 'editor message') start = time.time() # Fetch the summaries of all the threads. feedback_services.get_exp_thread_summaries(self.user_id, thread_ids) elapsed_time = time.time() - start self.assertLessEqual(elapsed_time, 1.7)
def post(self): """Handles POST requests.""" if len(self.normalized_payload.get('paginated_threads_list')) == 0: full_thread_ids = ( subscription_services.get_all_threads_subscribed_to( self.user_id)) paginated_threads_list = [ full_thread_ids[index:index + 100] for index in range(0, len(full_thread_ids), 100) ] else: paginated_threads_list = self.normalized_payload.get( 'paginated_threads_list') if (len(paginated_threads_list) > 0 and len(paginated_threads_list[0]) > 0): thread_summaries, number_of_unread_threads = ( feedback_services.get_exp_thread_summaries( self.user_id, paginated_threads_list[0])) else: thread_summaries, number_of_unread_threads = [], 0 self.values.update({ 'thread_summaries': [s.to_dict() for s in thread_summaries], 'number_of_unread_threads': number_of_unread_threads, 'paginated_threads_list': paginated_threads_list[1:] }) self.render_json(self.values)
def get(self): """Handles GET requests.""" full_thread_ids = subscription_services.get_all_threads_subscribed_to( self.user_id) if len(full_thread_ids) > 0: thread_summaries, number_of_unread_threads = ( feedback_services.get_exp_thread_summaries( self.user_id, full_thread_ids)) else: thread_summaries, number_of_unread_threads = [], 0 self.values.update({ 'thread_summaries': [s.to_dict() for s in thread_summaries], 'number_of_unread_threads': number_of_unread_threads, }) self.render_json(self.values)
def get(self): """Handles GET requests.""" ( learner_progress, number_of_nonexistent_activities, completed_to_incomplete_collections) = ( learner_progress_services.get_activity_progress(self.user_id)) completed_exp_summary_dicts = ( summary_services.get_displayable_exp_summary_dicts( learner_progress.completed_exp_summaries)) incomplete_exp_summary_dicts = ( summary_services.get_displayable_exp_summary_dicts( learner_progress.incomplete_exp_summaries)) completed_collection_summary_dicts = ( learner_progress_services.get_collection_summary_dicts( learner_progress.completed_collection_summaries)) incomplete_collection_summary_dicts = ( learner_progress_services.get_collection_summary_dicts( learner_progress.incomplete_collection_summaries)) exploration_playlist_summary_dicts = ( summary_services.get_displayable_exp_summary_dicts( learner_progress.exploration_playlist_summaries)) collection_playlist_summary_dicts = ( learner_progress_services.get_collection_summary_dicts( learner_progress.collection_playlist_summaries)) full_thread_ids = subscription_services.get_all_threads_subscribed_to( self.user_id) if len(full_thread_ids) > 0: thread_summaries, number_of_unread_threads = ( feedback_services.get_exp_thread_summaries( self.user_id, full_thread_ids)) else: thread_summaries, number_of_unread_threads = [], 0 creators_subscribed_to = ( subscription_services.get_all_creators_subscribed_to(self.user_id)) creators_settings = user_services.get_users_settings( creators_subscribed_to) subscription_list = [] for index, creator_settings in enumerate(creators_settings): subscription_summary = { 'creator_picture_data_url': ( creator_settings.profile_picture_data_url), 'creator_username': creator_settings.username, 'creator_impact': ( user_services.get_user_impact_score( creators_subscribed_to[index])) } subscription_list.append(subscription_summary) self.values.update({ 'completed_explorations_list': completed_exp_summary_dicts, 'completed_collections_list': completed_collection_summary_dicts, 'incomplete_explorations_list': incomplete_exp_summary_dicts, 'incomplete_collections_list': incomplete_collection_summary_dicts, 'exploration_playlist': exploration_playlist_summary_dicts, 'collection_playlist': collection_playlist_summary_dicts, 'number_of_nonexistent_activities': ( number_of_nonexistent_activities), 'completed_to_incomplete_collections': ( completed_to_incomplete_collections), 'thread_summaries': [s.to_dict() for s in thread_summaries], 'number_of_unread_threads': number_of_unread_threads, 'subscription_list': subscription_list }) self.render_json(self.values)