Skip to content

Commit 7a58c41

Browse files
authored
Merge pull request #670 from sartography/dev
Added some logging to troubleshoot the latest slowdown
2 parents 26e8278 + ff64ae9 commit 7a58c41

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

crc/api/study.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
from flask import g, send_file
55
from sqlalchemy.exc import IntegrityError
6-
from crc import session
6+
from crc import app, session
77
from crc.api.common import ApiError, ApiErrorSchema
88
from crc.models.study import Study, StudyEventType, StudyModel, StudySchema, StudyForUpdateSchema, \
99
StudyStatus, StudyAssociatedSchema, ProgressStatus, Category
1010
from crc.models.task_log import TaskLogQuery, TaskLogQuerySchema
1111
from crc.services.spreadsheet_service import SpreadsheetService
12-
from crc.services.study_service import StudyService
12+
from crc.services.study_service import StudyService, time_it
1313
from crc.services.task_logging_service import TaskLoggingService
1414
from crc.services.user_service import UserService
1515
from crc.services.workflow_processor import WorkflowProcessor
@@ -158,13 +158,25 @@ def delete_study(study_id):
158158

159159
def user_studies():
160160
"""Returns all the studies associated with the current user. """
161+
app.logger.info("Getting user studies")
162+
last_time = time_it('user_studies')
161163
user = UserService.current_user(allow_admin_impersonate=True)
164+
last_time = time_it('user_studies', last_time)
162165
spec_service = WorkflowSpecService()
166+
last_time = time_it('user_studies', last_time)
163167
specs = spec_service.get_specs()
168+
last_time = time_it('user_studies', last_time)
164169
cats = spec_service.get_categories()
170+
app.logger.info("Before sync with protocol builder")
171+
last_time = time_it('user_studies', last_time)
165172
StudyService().sync_with_protocol_builder_if_enabled(user, specs)
173+
app.logger.info("After sync with protocol builder")
174+
last_time = time_it('user_studies', last_time)
166175
studies = StudyService().get_studies_for_user(user, categories=cats)
167-
176+
177+
app.logger.info("Have user studies")
178+
last_time = time_it('user_studies', last_time)
179+
168180
# Disable this check - we don't want to raise this error.
169181
# if len(studies) == 0:
170182
# studies = StudyService().get_studies_for_user(user, categories=cats, include_invalid=True)

crc/services/study_service.py

+25
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@
3232
from crc.services.user_file_service import UserFileService
3333
from crc.services.workflow_processor import WorkflowProcessor
3434

35+
import time
36+
37+
38+
def time_it(method, last_time=None):
39+
now = time.time()
40+
if last_time:
41+
app.logger.info(f"{method}: Time since last time: {now - last_time}")
42+
else:
43+
app.logger.info(f"{method}: First time: {now}")
44+
return now
45+
3546

3647
class StudyService(object):
3748
"""Provides common tools for working with a Study"""
@@ -572,13 +583,18 @@ def __delete_exempt_studies(self, exempt_studies):
572583

573584
@staticmethod
574585
def __abandon_missing_studies(missing_studies, db_studies):
586+
last_time = time_it('__abandon_missing_studies')
587+
app.logger.info("loop through missing studies")
575588
for missing_study_id in missing_studies:
589+
last_time = time_it('__abandon_missing_studies', last_time)
576590
study = next((s for s in db_studies if s.id == missing_study_id), None)
577591
if study and study.status != StudyStatus.abandoned:
592+
app.logger.info("add updtae event")
578593
study.status = StudyStatus.abandoned
579594
StudyService.add_study_update_event(study,
580595
status=StudyStatus.abandoned,
581596
event_type=StudyEventType.automatic)
597+
app.logger.info("end loop through missing studies")
582598

583599
def sync_with_protocol_builder_if_enabled(self, user, specs):
584600
"""Assures that the studies we have locally for the given user are
@@ -588,6 +604,7 @@ def sync_with_protocol_builder_if_enabled(self, user, specs):
588604

589605
app.logger.info("The Protocol Builder is enabled. app.config['PB_ENABLED'] = " +
590606
str(app.config['PB_ENABLED']))
607+
last_time = time_it('sync_with_protocol_builder_if_enabled')
591608

592609
# Get studies matching this user from Protocol Builder
593610
if user:
@@ -596,19 +613,27 @@ def sync_with_protocol_builder_if_enabled(self, user, specs):
596613
else:
597614
pb_studies = []
598615

616+
last_time = time_it('sync_with_protocol_builder_if_enabled', last_time)
599617
# Get studies from the database
600618
db_studies = session.query(StudyModel).filter_by(user_uid=user.uid).all()
601619

602620
# Update all studies from the protocol builder, create new studies as needed.
603621
# Further assures that every active study (that does exist in the protocol builder)
604622
# has a reference to every available workflow (though some may not have started yet)
623+
last_time = time_it('sync_with_protocol_builder_if_enabled', last_time)
605624
self.__process_pb_studies(pb_studies, db_studies, user, specs)
606625

607626
# Process studies in the DB that are no longer in Protocol Builder
627+
last_time = time_it('sync_with_protocol_builder_if_enabled', last_time)
608628
missing_studies, exempt_studies = \
609629
self.__get_missing_and_exempt_studies(db_studies, pb_studies)
630+
last_time = time_it('sync_with_protocol_builder_if_enabled', last_time)
610631
self.__delete_exempt_studies(exempt_studies)
632+
app.logger.info("Before abandon missing studies")
633+
last_time = time_it('sync_with_protocol_builder_if_enabled', last_time)
611634
self.__abandon_missing_studies(missing_studies, db_studies)
635+
app.logger.info("After abandon missing studies")
636+
time_it('sync_with_protocol_builder_if_enabled', last_time)
612637

613638
@staticmethod
614639
def add_study_update_event(study, status, event_type, user_uid=None, comment=''):

0 commit comments

Comments
 (0)