Projet

Général

Profil

0002-caluire-axel-caching-for-family_data-53853.patch

Lauréline Guérin, 10 mai 2021 11:58

Télécharger (3,2 ko)

Voir les différences:

Subject: [PATCH 2/2] caluire-axel: caching for family_data (#53853)

 passerelle/contrib/caluire_axel/models.py |  6 ++++++
 tests/test_caluire_axel.py                | 12 ++++++++++++
 2 files changed, 18 insertions(+)
passerelle/contrib/caluire_axel/models.py
16 16

  
17 17
import datetime
18 18

  
19
from django.core.cache import cache
19 20
from django.db import models
20 21
from django.utils.translation import ugettext_lazy as _
21 22

  
......
133 134
        return {'link': link_id, 'deleted': True, 'family_id': link.family_id}
134 135

  
135 136
    def get_family_data(self, family_id):
137
        cache_key = 'caluire-axel-%s-family-data-%s' % (self.pk, family_id)
138
        result = cache.get(cache_key)
139
        if result is not None:
140
            return result
136 141
        try:
137 142
            result = schemas.get_famille_individus(
138 143
                self, {'PORTAIL': {'GETFAMILLE': {'IDENTFAMILLE': family_id}}}
......
150 155
            child['id'] = child['IDENT']
151 156
            child['text'] = '{} {}'.format(child['PRENOM'].strip(), child['NOM'].strip()).strip()
152 157

  
158
        cache.set(cache_key, family_data, 30)  # 30 seconds
153 159
        return family_data
154 160

  
155 161
    def get_child_data(self, family_id, child_id):
tests/test_caluire_axel.py
471 471
    assert resp.json['data']['MEMBRE'][3]['id'] == '59509'
472 472
    assert resp.json['data']['MEMBRE'][3]['text'] == 'Enfant 5 CALUIRE TEST'
473 473

  
474
    # again - data are in cache
475
    resp = app.get('/caluire-axel/test/family_info?NameID=yyy')
476
    assert resp.json['err'] == 0
477

  
474 478

  
475 479
def test_children_info_endpoint_axel_error(app, resource):
476 480
    Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
......
505 509
    assert resp.json['data'][3]['id'] == '59509'
506 510
    assert resp.json['data'][3]['text'] == 'Enfant 5 CALUIRE TEST'
507 511

  
512
    # again - data are in cache
513
    resp = app.get('/caluire-axel/test/children_info?NameID=yyy')
514
    assert resp.json['err'] == 0
515

  
508 516

  
509 517
def test_child_info_endpoint_axel_error(app, resource):
510 518
    Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
......
561 569
    assert resp.json['data']['id'] == '50632'
562 570
    assert resp.json['data']['text'] == 'Enfant 1 CALUIRE TEST'
563 571

  
572
    # again - data are in cache
573
    resp = app.get('/caluire-axel/test/child_info?NameID=yyy&idpersonne=50632')
574
    assert resp.json['err'] == 0
575

  
564 576

  
565 577
def test_child_schooling_info_endpoint_axel_error(app, resource):
566 578
    Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
567
-