Skip to content

Commit

Permalink
Fix/issue 76 (#77)
Browse files Browse the repository at this point in the history
* Increase gunicorn timeout

* Improve quality assessment table performance

* Add newsfragment
  • Loading branch information
vitorfs authored Sep 10, 2021
1 parent 3c71f18 commit f97ee87
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 32 deletions.
2 changes: 2 additions & 0 deletions bin/gunicorn_start
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ DIR=/home/parsifal/parsifal
USER=parsifal
GROUP=parsifal
WORKERS=3
TIMEOUT=120
BIND=unix:/home/parsifal/run/gunicorn.sock
DJANGO_SETTINGS_MODULE=parsifal.settings.production
DJANGO_WSGI_MODULE=parsifal.wsgi
Expand All @@ -18,6 +19,7 @@ export PYTHONPATH=$DIR:$PYTHONPATH
exec /home/parsifal/venv/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $WORKERS \
--timeout $TIMEOUT \
--user=$USER \
--group=$GROUP \
--bind=$BIND \
Expand Down
58 changes: 28 additions & 30 deletions parsifal/apps/reviews/conducting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
from django.conf import settings as django_settings
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.db.models import Count
from django.db.models import Count, Sum, Value
from django.db.models.functions import Coalesce
from django.http import Http404, HttpResponse, HttpResponseBadRequest
from django.shortcuts import get_object_or_404, redirect, render
from django.template.context_processors import csrf
from django.urls import reverse as r
from django.utils.html import escape
from django.utils.html import escape, format_html
from django.utils.translation import gettext as _
from django.views.decorators.http import require_POST

Expand Down Expand Up @@ -227,7 +228,12 @@ def study_selection(request, username, review_name):


def build_quality_assessment_table(request, review, order):
selected_studies = review.get_accepted_articles().order_by(order)
selected_studies = (
review.get_accepted_articles()
.prefetch_related("qualityassessment_set")
.annotate(score=Coalesce(Sum("qualityassessment__answer__weight"), Value(0.0)))
.order_by(order)
)
quality_questions = review.get_quality_assessment_questions()
quality_answers = review.get_quality_assessment_answers()

Expand All @@ -242,43 +248,35 @@ def build_quality_assessment_table(request, review, order):
<table class="table" id="tbl-quality" article-id="{2}" csrf-token="{3}">
<tbody>""".format(
escape(study.title), study.get_score(), study.id, str(csrf(request)["csrf_token"]), escape(study.year)
escape(study.title), study.score, study.id, str(csrf(request)["csrf_token"]), escape(study.year)
)

quality_assessment = study.get_quality_assesment()

for question in quality_questions:
str_table += (
'''<tr question-id="'''
+ str(question.id)
+ """">
<td>"""
+ escape(question.description)
+ """</td>"""
str_table += format_html(
'<tr question-id="{question_id}"><td>{question_description}</td>',
question_id=question.pk,
question_description=question.description,
)

try:
question_answer = quality_assessment.filter(question__id=question.id).get()
except Exception:
question_answer = None
question_answer_id = None
for qa in study.qualityassessment_set.all():
if qa.question_id == question.pk:
question_answer_id = qa.answer_id
break

for answer in quality_answers:
selected_answer = ""
if question_answer is not None:
if answer.id == question_answer.answer.id:
selected_answer = " selected-answer"
str_table += (
"""<td class="answer"""
+ selected_answer
+ '''" answer-id="'''
+ str(answer.id)
+ """">"""
+ escape(answer.description)
+ """</td>"""
if answer.id == question_answer_id:
selected_answer = " selected-answer"
str_table += format_html(
'<td class="answer {selected}" answer-id="{answer_id}">{answer_description}</td>',
selected=selected_answer,
answer_id=answer.pk,
answer_description=answer.description,
)
str_table += """</tr>"""
str_table += "</tr>"

str_table += """</tbody></table></div>"""
str_table += "</tbody></table></div>"
return str_table
else:
return ""
Expand Down
23 changes: 23 additions & 0 deletions parsifal/apps/reviews/migrations/0037_auto_20210910_0311.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.7 on 2021-09-10 03:11

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('reviews', '0036_auto_20210906_2320'),
]

operations = [
migrations.AlterField(
model_name='article',
name='title',
field=models.CharField(blank=True, db_index=True, max_length=1000, null=True),
),
migrations.AlterField(
model_name='article',
name='year',
field=models.CharField(blank=True, db_index=True, max_length=10, null=True),
),
]
4 changes: 2 additions & 2 deletions parsifal/apps/reviews/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ class Article(models.Model):

review = models.ForeignKey(Review, on_delete=models.CASCADE)
bibtex_key = models.CharField(max_length=100)
title = models.CharField(max_length=1000, null=True, blank=True)
title = models.CharField(max_length=1000, null=True, blank=True, db_index=True)
author = models.CharField(max_length=1000, null=True, blank=True)
journal = models.CharField(max_length=1000, null=True, blank=True)
year = models.CharField(max_length=10, null=True, blank=True)
year = models.CharField(max_length=10, null=True, blank=True, db_index=True)
source = models.ForeignKey(Source, on_delete=models.CASCADE, null=True)
pages = models.CharField(max_length=20, null=True, blank=True)
volume = models.CharField(max_length=100, null=True, blank=True)
Expand Down
1 change: 1 addition & 0 deletions parsifal/newsfragments/76.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve quality assessment table performance.

0 comments on commit f97ee87

Please sign in to comment.