Skip to content

Commit

Permalink
perf optimizations in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
oTree-org committed Oct 16, 2017
1 parent 4fa74f9 commit 6721cc9
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 10 deletions.
2 changes: 1 addition & 1 deletion otree/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from importlib import import_module as _import_module

from otree.constants import BaseConstants # noqa
from otree.models import BaseSubsession, BaseGroup, BasePlayer # noqa
from otree.constants import BaseConstants # noqa
from otree.views import Page, WaitPage # noqa
from otree.common import Currency, currency_range, safe_json # noqa
from otree.bots import Bot, Submission, SubmissionMustFail # noqa
Expand Down
1 change: 1 addition & 0 deletions otree/channels/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@

]

# TODO: perf issue. this takes 0.1-0.5 seconds.
for extensions_module in get_extensions_modules('routing'):
channel_routing += getattr(extensions_module, 'channel_routing', [])
2 changes: 2 additions & 0 deletions otree/checks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ def files(rules, **kwargs):
rules.file_exists('views.py')

if os.path.isdir(rules.get_path('templates')):

# check for files in templates, but not in templates/<label>

misplaced_templates = set(glob.glob(
os.path.join(rules.get_path('templates'), '*.html')
))
Expand Down
1 change: 1 addition & 0 deletions otree/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def get(self, request, *args, **kwargs):
"""

def get_extensions_modules(submodule_name):
'''TODO: performance issue. this 'autodiscover' adds to oTree startup time'''
modules = []
for app_config in apps.get_app_configs():
try:
Expand Down
2 changes: 2 additions & 0 deletions otree/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
# project I wouldn't do it this way, but because oTree is aimed at newcomers
# who may need more assistance from their IDE, I want to try this approach out.
# this module is also a form of documentation of the public API.

subsession_module = import_module('otree.models.subsession')
group_module = import_module('otree.models.group')
player_module = import_module('otree.models.player')


# so that oTree users don't see internal details
session_module = import_module('otree.models.session')
participant_module = import_module('otree.models.participant')
Expand Down
14 changes: 12 additions & 2 deletions otree/models/session.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import logging
import channels
import json
import django.test
from django.core.urlresolvers import reverse

from otree import constants_internal
Expand All @@ -12,14 +12,17 @@
random_chars_8, random_chars_10, get_admin_secret_code,
get_app_label_from_name
)


from otree.db import models
from otree.models_concrete import ParticipantToPlayerLookup, RoomToSession
from django.template.loader import get_template
from django.template import TemplateDoesNotExist
from .varsmixin import ModelWithVars


logger = logging.getLogger('otree')

client = django.test.Client()

ADMIN_SECRET_CODE = get_admin_secret_code()

Expand Down Expand Up @@ -144,6 +147,13 @@ def mturk_worker_url(self):
).format(self.mturk_HITGroupId)

def advance_last_place_participants(self):
# django.test takes 0.5 sec to import,
# if this is done globally then it adds to each startup
# it's only used here, and often isn't used at all.
# so best to do it only here
# it gets cached
import django.test
client = django.test.Client()

participants = self.get_participants()

Expand Down
8 changes: 8 additions & 0 deletions otree/models/subsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ def group_like_round(self, round_number):

self.set_group_matrix(group_matrix)

def new_group_like_round(self, round_number):
'''test this, could work'''
matrix = self.in_round(round_number).get_group_matrix()
for row in matrix:
for col in row:
matrix[row][col] = matrix[row][col].id_in_subsession
self.set_group_matrix(matrix)

'''
def group_like_round(self, round_number):
PlayerClass = self._PlayerClass()
Expand Down
4 changes: 3 additions & 1 deletion otree/project_template/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ staticfiles
.idea
*~
*.sqlite3
_coverage_results/
_coverage_results
_static_root
_bots*s
13 changes: 8 additions & 5 deletions otree/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ def get_default_settings(initial_settings=None):
},
'sentry': {
'level': 'WARNING',
'class': (
'raven.contrib.django.raven_compat.handlers.'
'SentryHandler'
),
'class': 'logging.StreamHandler',
#'class': (
# 'raven.contrib.django.raven_compat.handlers.'
# 'SentryHandler'
#),
},
},
'loggers': {
Expand Down Expand Up @@ -236,6 +237,7 @@ def augment_settings(settings):
'idmap',
]


if settings.get('SENTRY_DSN'):
settings.setdefault(
'RAVEN_CONFIG',
Expand All @@ -244,7 +246,8 @@ def augment_settings(settings):
'processors': ['raven.processors.SanitizePasswordsProcessor'],
}
)
no_experiment_apps.append('raven.contrib.django.raven_compat')
#no_experiment_apps.append('raven.contrib.django.raven_compat')


# order is important:
# otree unregisters User & Group, which are installed by auth.
Expand Down
2 changes: 1 addition & 1 deletion tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

INSTALLED_APPS = [
'otree',
'raven.contrib.django.raven_compat',
#'raven.contrib.django.raven_compat',
'tests',
]

Expand Down

0 comments on commit 6721cc9

Please sign in to comment.