Changeset 627

Show
Ignore:
Timestamp:
09/22/10 10:39:26 (3 years ago)
Author:
jose.brandao
Message:

Improving assistence.views.faq to use better the database and cache resources

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/buildout.cfg

    r618 r627  
    3333    django-rosetta 
    3434    django-registration 
     35    django-reversion 
    3536 
    3637[django] 
  • trunk/opentrials/assistance/views.py

    r626 r627  
    99 
    1010def faq(request): 
    11     questions = Question.objects.all().order_by('category', 'order') 
     11    """ 
     12    ATTENTION: This view has a complexity of O(question * N * 2) on database load, because each 
     13    question does 1 or 2 calls to database to get question and category translations. 
     14 
     15    It is prepared to get questions including category fields at once SQL call and using cache 
     16    to get translations as far as possible. 
     17 
     18    If the questions quantity grow a lot, this logic should be replaced to something that gets 
     19    all translations from database at once. 
     20    """ 
     21    questions = Question.objects.select_related('category').order_by('category', 'order') 
    1222 
    1323    if len(questions) < 1: 
     
    1929            c = Category() 
    2030            try: 
    21                 trans = question.translations.get(language__iexact=request.LANGUAGE_CODE) 
     31                #trans = question.translations.get(language__iexact=request.LANGUAGE_CODE) 
     32                trans = QuestionTranslation.objects.get_translation_for_object(request.LANGUAGE_CODE, question) 
    2233                q.title = trans.title 
    2334                q.answer = trans.answer 
     
    2738                q = question 
    2839            try: 
    29                 trans = question.category.translations.get(language__iexact=request.LANGUAGE_CODE) 
     40                #trans = question.category.translations.get(language__iexact=request.LANGUAGE_CODE) 
     41                trans = CategoryTranslation.objects.get_translation_for_object(request.LANGUAGE_CODE, question.category) 
    3042                c.label = trans.label 
    3143            except CategoryTranslation.DoesNotExist: