diff --git a/.gitignore b/.gitignore index 1ff4b346513763a68ed8d2a1c14cce95bf835e62..e8d72a0a452ed32314551a62ab07bd3b47b326d3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ dist *.egg-info *.pyc *~ -djangoldp/tests/tests_temp.py diff --git a/README.md b/README.md index 3fe81ecc4a31199abfe5e80893f6d8202b103318..94f9d2915aa8dd4c5db91405fd858693c4f977ac 100644 --- a/README.md +++ b/README.md @@ -126,14 +126,12 @@ LDP_RDF_CONTEXT = 'https://cdn.happy-dev.fr/owl/hdcontext.jsonld' DJANGOLDP_PACKAGES = [] SITE_URL = 'http://localhost:8000' BASE_URL = SITE_URL -PERMISSIONS_CACHE = True ``` * `LDP_RDF_CONTEXT` tells DjangoLDP where our RDF [ontology](https://www.w3.org/standards/semanticweb/ontology) is defined, which will be returned as part of our views in the 'context' field. This is a web URL and you can visit the value to view the full ontology online. The ontology can be a string, as in the example, but it can also be a dictionary, or a list of ontologies (see the [JSON-LD spec](https://json-ld.org) for examples) * `DJANGOLDP_PACKAGES` defines which other [DjangoLDP packages](https://git.happy-dev.fr/startinblox/djangoldp-packages) we're using in this installation * `SITE_URL` is the URL serving the site, e.g. `https://example.com/`. Note that if you include the DjangoLDP urls in a nested path (e.g. `https://example.com/api/`), then `SITE_URL` will need to be set to this value * `BASE_URL` may be different from SITE_URL, e.g. `https://example.com/app/` -* `PERMISSIONS_CACHE` Activate cache on Permissions (Set to True Recommended) 4. You can also register your model for the django administration site diff --git a/djangoldp/serializers.py b/djangoldp/serializers.py index 710d1bff4f1ea49cef00bf7ba1dd54a5353c70e9..6fc13ee35bced56e0ad4bd1533a72e2d31e1d782 100644 --- a/djangoldp/serializers.py +++ b/djangoldp/serializers.py @@ -1,3 +1,4 @@ +import time import uuid from collections import OrderedDict, Mapping, Iterable from typing import Any @@ -27,10 +28,40 @@ from djangoldp.models import Model from djangoldp.permissions import LDPPermissions +class InMemoryCache: + + def __init__(self): + self.cache = { + 'time': time.time() + } + + def invalidate_cache(self): + self.cache = { + 'time': time.time() + } + + def refresh_cache(self): + if time.time() - self.cache['time'] > 5: + self.invalidate_cache() + + def has(self, cache_key): + return cache_key in self.cache + + def get(self, cache_key): + return self.cache[cache_key] + + def set(self, cache_key, value): + self.cache[cache_key] = value + + class LDListMixin: '''A Mixin for serializing containers into JSONLD format''' child_attr = 'child' + with_cache = getattr(settings, 'SERIALIZER_CACHE', True) + + to_representation_cache = InMemoryCache() + # converts primitive data representation to the representation used within our application def to_internal_value(self, data): try: @@ -56,6 +87,7 @@ class LDListMixin: - Can Add if add permission on contained object's type - Can view the container is view permission on container model : container obj are filtered by view permission ''' + self.to_representation_cache.refresh_cache() try: child_model = getattr(self, self.child_attr).Meta.model except AttributeError: @@ -67,8 +99,16 @@ class LDListMixin: value = list(value) if not isinstance(value, Iterable): + if not self.id.startswith('http'): + self.id = '{}{}{}'.format(settings.BASE_URL, Model.resource(parent_model), self.id) + + cache_key = self.id + if self.with_cache and self.to_representation_cache.has(cache_key): + return self.to_representation_cache.get(cache_key) + filtered_values = value container_permissions = Model.get_permissions(child_model, self.context['request'].user, ['view', 'add']) + else: # this is a container. Parent model is the containing object, child the model contained try: @@ -76,6 +116,13 @@ class LDListMixin: except: parent_model = child_model + if not self.id.startswith('http'): + self.id = '{}{}{}'.format(settings.BASE_URL, Model.resource(parent_model), self.id) + + cache_key = self.id + if self.with_cache and self.to_representation_cache.has(cache_key): + return self.to_representation_cache.get(cache_key) + # remove objects from the list which I don't have permission to view filtered_values = list( filter(lambda v: Model.get_permission_classes(v, [LDPPermissions])[0]().has_object_permission( @@ -84,13 +131,14 @@ class LDListMixin: container_permissions.extend( Model.get_permissions(parent_model, self.context['request'].user, ['view'])) - if not self.id.startswith('http'): - self.id = '{}{}{}'.format(settings.BASE_URL, Model.resource(parent_model), self.id) - return {'@id': self.id, + + self.to_representation_cache.set(self.id, {'@id': self.id, '@type': 'ldp:Container', 'ldp:contains': super().to_representation(filtered_values), 'permissions': container_permissions - } + }) + + return self.to_representation_cache.get(self.id) def get_attribute(self, instance): parent_id_field = self.parent.fields[self.parent.url_field_name] @@ -256,6 +304,10 @@ class LDPSerializer(HyperlinkedModelSerializer): serializer_url_field = JsonLdIdentityField ModelSerializer.serializer_field_mapping[LDPUrlField] = IdURLField + with_cache = getattr(settings, 'SERIALIZER_CACHE', True) + + to_representation_cache = InMemoryCache() + def get_default_field_names(self, declared_fields, model_info): try: fields = list(self.Meta.model._meta.serializer_fields) @@ -265,10 +317,18 @@ class LDPSerializer(HyperlinkedModelSerializer): def to_representation(self, obj): # external Models should only be returned with an id (on GET) + self.to_representation_cache.refresh_cache() if self.context['request'].method == 'GET' and Model.is_external(obj): return {'@id': obj.urlid} - data = super().to_representation(obj) + if self.with_cache and hasattr(obj, 'urlid'): + if self.to_representation_cache.has(obj.urlid): + data = self.to_representation_cache.get(obj.urlid) + else: + data = super().to_representation(obj) + self.to_representation_cache.set(obj.urlid, data) + else: + data = super().to_representation(obj) slug_field = Model.slug_field(obj) for field in data: diff --git a/djangoldp/tests/perf_result.csv b/djangoldp/tests/perf_result.csv index 11d53c63dc97b3032f1fc85ef4f26e1edac70a6f..33d2f033490923f81080c5ac54527b537eb97bb3 100644 --- a/djangoldp/tests/perf_result.csv +++ b/djangoldp/tests/perf_result.csv @@ -1,38 +1,49 @@ -Machine,Date,Auth,WithPermsCache,volume,test+AF8-get+AF8-resource,test+AF8-get+AF8-container,test+AF8-get+AF8-filtered+AF8-fields,test+AF8-get+AF8-reverse+AF8-filtered+AF8-fields,test+AF8-get+AF8-nested,test+AF8-get+AF8-users+AF8-container,Prefetch -jbl+AC0-T440p,Sep 22 2020 10:50:51,False,False,200,0.003339644670486,0.006944504976273,0.038935685157776,0.024031536579132,0.000708421468735,,FALSE -jbl+AC0-T440p,Sep 22 2020 10:51:46,False,False,200,0.0035072016716,0.006944673061371,0.039835988283157,0.025360778570175,0.000757339000702,,FALSE -jbl+AC0-T440p,Sep 22 2020 10:52:42,False,False,200,0.003284044265747,0.006942090988159,0.038870732784271,0.023859632015228,0.000705161094666,,FALSE -jbl+AC0-T440p,Sep 22 2020 10:53:16,False,False,100,0.003656179904938,0.005776383876801,0.025797350406647,0.01539302110672,0.000770201683044,,FALSE -jbl+AC0-T440p,Sep 22 2020 10:53:33,False,False,100,0.003554759025574,0.005703027248383,0.024777753353119,0.015221126079559,0.000770528316498,,FALSE -jbl+AC0-T440p,Sep 22 2020 10:53:49,False,False,100,0.003367004394531,0.005602278709412,0.023594326972962,0.014168989658356,0.000726828575134,,FALSE -jbl+AC0-T440p,Sep 22 2020 10:54:03,False,False,50,0.003355793952942,0.005232772827148,0.016062431335449,0.009248399734497,0.000776686668396,,FALSE -jbl+AC0-T440p,Sep 22 2020 10:54:09,False,False,50,0.003454508781433,0.005315055847168,0.016247057914734,0.009447617530823,0.00073832988739,,FALSE -jbl+AC0-T440p,Sep 22 2020 10:54:15,False,False,50,0.003420171737671,0.005717425346375,0.016275815963745,0.009424614906311,0.001325125694275,,FALSE -jbl+AC0-T440p,Sep 22 2020 10:57:41,False,False,300,0.003357520103455,0.009047945340474,0.055130259990692,0.033688295682271,0.000706691741943,,FALSE -jbl+AC0-T440p,Sep 22 2020 10:59:35,False,False,300,0.003680046399434,0.009138919512431,0.056478141943614,0.0363059147199,0.000769446690877,,FALSE -jbl+AC0-T440p,Sep 22 2020 11:01:29,False,False,300,0.003643860816956,0.008885918458303,0.059775860309601,0.035221153100332,0.000756018956502,,FALSE -jbl+AC0-T440p,Sep 22 2020 11:47:40,False,False,100,0.003384988307953,0.006034939289093,0.024095425605774,0.014140074253082,0.000722093582153,,FALSE -jbl+AC0-T440p,Sep 22 2020 11:47:57,False,False,100,0.003611071109772,0.005775241851807,0.023724327087402,0.014749829769135,0.000745611190796,,FALSE -jbl+AC0-T440p,Sep 22 2020 11:48:15,False,False,100,0.003316740989685,0.005551462173462,0.023505146503449,0.014274184703827,0.000737235546112,,FALSE -jbl+AC0-T440p,Sep 22 2020 11:51:06,False,False,200,0.003252120018005,0.006922056674957,0.038872839212418,0.025012502670288,0.000715854167938,,FALSE -jbl+AC0-T440p,Sep 22 2020 11:52:07,False,False,200,0.003315222263336,0.007173013687134,0.039467182159424,0.0239526450634,0.000736322402954,,FALSE -jbl+AC0-T440p,Sep 22 2020 11:53:59,False,False,200,0.003276619911194,0.006898198127747,0.038627609014511,0.023467609882355,0.000708512067795,,FALSE -jbl+AC0-T440p,Sep 23 2020 15:19:39,True,False,100,0.006617827415466,0.245147013664246,0.261345520019531,0.209938230514526,0.001274492740631,0.01203465461731,TRUE -jbl+AC0-T440p,Sep 23 2020 15:23:58,True,False,100,0.006518981456757,0.263970799446106,0.139407794475555,0.113074848651886,0.001235642433167,0.642078399658203,TRUE -jbl+AC0-T440p,Sep 23 2020 15:25:33,True,False,100,0.006539282798767,0.263329057693481,0.143536510467529,0.115545327663422,0.00125715970993,0.520937442779541,TRUE -jbl+AC0-T440p,Sep 23 2020 15:47:31,True,True,100,0.003864502906799,0.019258742332459,0.01636646270752,0.008915212154388,0.000782597064972,0.354249000549316,TRUE -jbl+AC0-T440p,Sep 23 2020 15:48:30,True,True,100,0.003590517044067,0.019879310131073,0.016916983127594,0.009615495204926,0.000798478126526,0.364127635955811,TRUE -jbl+AC0-T440p,Sep 23 2020 15:49:19,True,True,100,0.003716588020325,0.023860175609589,0.016380727291107,0.009003615379334,0.000774307250977,0.35044002532959,TRUE -jbl+AC0-T440p,Sep 23 2020 16:56:57,True,True,100,0.004425497055054,0.019956090450287,0.017114706039429,0.010911240577698,0.000832149982452,0.336694478988647,TRUE -jbl+AC0-T440p,Sep 23 2020 16:57:23,True,True,100,0.004397692680359,0.021222379207611,0.01826550245285,0.010625832080841,0.000812151432037,0.344640016555786,TRUE -jbl+AC0-T440p,Sep 23 2020 16:57:45,True,True,100,0.004602279663086,0.020297501087189,0.017129955291748,0.010850946903229,0.000865814685822,0.339866161346436,TRUE -jbl+AC0-T440p,Sep 23 2020 16:58:37,True,True,200,0.004463336467743,0.036689649820328,0.025502071380615,0.015932221412659,0.000898872613907,0.681740045547485,TRUE -jbl+AC0-T440p,Sep 23 2020 16:59:37,True,True,200,0.004517335891724,0.036278907060623,0.025654143095017,0.01576028585434,0.000849905014038,0.660790681838989,TRUE -jbl+AC0-T440p,Sep 23 2020 17:14:05,True,False,100,0.006808481216431,0.252511320114136,0.139744215011597,0.111351528167725,0.001188087463379,0.564764976501465,TRUE -jbl+AC0-T440p,Sep 23 2020 17:16:58,True,False,100,0.006502165794373,0.242799952030182,0.137602522373199,0.108403618335724,0.001143708229065,0.556174516677856,TRUE -jbl+AC0-T440p,Sep 24 2020 06:53:53,True,False,100,0.007479875087738,0.252197952270508,0.141312582492828,0.109222292900085,0.001601278781891,0.52592396736145,TRUE -jbl+AC0-T440p,Sep 24 2020 06:56:06,True,False,100,0.020340206623077,1.31586099863052,0.729812262058258,0.577438371181488,0.00078241109848,1.78533124923706,FALSE -jbl+AC0-T440p,Sep 24 2020 07:04:00,True,False,100,0.006233677864075,0.242916750907898,0.135480484962463,0.10392139673233,0.000762076377869,0.569819927215576,TRUE -jbl+AC0-T440p,Sep 24 2020 07:05:19,True,True,100,0.006471273899078,0.023659512996674,0.020732533931732,0.015365273952484,0.000769484043121,0.549034357070923,FALSE -jbl+AC0-T440p,Sep 24 2020 07:05:50,True,True,100,0.005183663368225,0.021180493831635,0.016473467350006,0.010494797229767,0.000771188735962,0.321053028106689,TRUE -jbl+AC0-T440p,Sep 24 2020 07:33:51,True,True,100,0.004018228054047,0.019896368980408,0.024588730335236,0.015463829040527,0.000797684192657,0.375835657119751,TRUE +Machine,Date,Auth,WithPermsCache,volume,test+AF8-get+AF8-resource,test+AF8-get+AF8-container,test+AF8-get+AF8-filtered+AF8-fields,test+AF8-get+AF8-reverse+AF8-filtered+AF8-fields,test+AF8-get+AF8-nested,test+AF8-get+AF8-users+AF8-container,Prefetch,default depth +jbl+AC0-T440p,Sep 22 2020 10:50:51,False,False,200,0.003339644670486,0.006944504976273,0.038935685157776,0.024031536579132,0.000708421468735,,FALSE,0 +jbl+AC0-T440p,Sep 22 2020 10:51:46,False,False,200,0.0035072016716,0.006944673061371,0.039835988283157,0.025360778570175,0.000757339000702,,FALSE,0 +jbl+AC0-T440p,Sep 22 2020 10:52:42,False,False,200,0.003284044265747,0.006942090988159,0.038870732784271,0.023859632015228,0.000705161094666,,FALSE,0 +jbl+AC0-T440p,Sep 22 2020 10:53:16,False,False,100,0.003656179904938,0.005776383876801,0.025797350406647,0.01539302110672,0.000770201683044,,FALSE,0 +jbl+AC0-T440p,Sep 22 2020 10:53:33,False,False,100,0.003554759025574,0.005703027248383,0.024777753353119,0.015221126079559,0.000770528316498,,FALSE,0 +jbl+AC0-T440p,Sep 22 2020 10:53:49,False,False,100,0.003367004394531,0.005602278709412,0.023594326972962,0.014168989658356,0.000726828575134,,FALSE,0 +jbl+AC0-T440p,Sep 22 2020 10:54:03,False,False,50,0.003355793952942,0.005232772827148,0.016062431335449,0.009248399734497,0.000776686668396,,FALSE,0 +jbl+AC0-T440p,Sep 22 2020 10:54:09,False,False,50,0.003454508781433,0.005315055847168,0.016247057914734,0.009447617530823,0.00073832988739,,FALSE,0 +jbl+AC0-T440p,Sep 22 2020 10:54:15,False,False,50,0.003420171737671,0.005717425346375,0.016275815963745,0.009424614906311,0.001325125694275,,FALSE,0 +jbl+AC0-T440p,Sep 22 2020 10:57:41,False,False,300,0.003357520103455,0.009047945340474,0.055130259990692,0.033688295682271,0.000706691741943,,FALSE,0 +jbl+AC0-T440p,Sep 22 2020 10:59:35,False,False,300,0.003680046399434,0.009138919512431,0.056478141943614,0.0363059147199,0.000769446690877,,FALSE,0 +jbl+AC0-T440p,Sep 22 2020 11:01:29,False,False,300,0.003643860816956,0.008885918458303,0.059775860309601,0.035221153100332,0.000756018956502,,FALSE,0 +jbl+AC0-T440p,Sep 22 2020 11:47:40,False,False,100,0.003384988307953,0.006034939289093,0.024095425605774,0.014140074253082,0.000722093582153,,FALSE,0 +jbl+AC0-T440p,Sep 22 2020 11:47:57,False,False,100,0.003611071109772,0.005775241851807,0.023724327087402,0.014749829769135,0.000745611190796,,FALSE,0 +jbl+AC0-T440p,Sep 22 2020 11:48:15,False,False,100,0.003316740989685,0.005551462173462,0.023505146503449,0.014274184703827,0.000737235546112,,FALSE,0 +jbl+AC0-T440p,Sep 22 2020 11:51:06,False,False,200,0.003252120018005,0.006922056674957,0.038872839212418,0.025012502670288,0.000715854167938,,FALSE,0 +jbl+AC0-T440p,Sep 22 2020 11:52:07,False,False,200,0.003315222263336,0.007173013687134,0.039467182159424,0.0239526450634,0.000736322402954,,FALSE,0 +jbl+AC0-T440p,Sep 22 2020 11:53:59,False,False,200,0.003276619911194,0.006898198127747,0.038627609014511,0.023467609882355,0.000708512067795,,FALSE,0 +jbl+AC0-T440p,Sep 23 2020 15:19:39,True,False,100,0.006617827415466,0.245147013664246,0.261345520019531,0.209938230514526,0.001274492740631,0.01203465461731,TRUE,0 +jbl+AC0-T440p,Sep 23 2020 15:23:58,True,False,100,0.006518981456757,0.263970799446106,0.139407794475555,0.113074848651886,0.001235642433167,0.642078399658203,TRUE,0 +jbl+AC0-T440p,Sep 23 2020 15:25:33,True,False,100,0.006539282798767,0.263329057693481,0.143536510467529,0.115545327663422,0.00125715970993,0.520937442779541,TRUE,0 +jbl+AC0-T440p,Sep 23 2020 15:47:31,True,True,100,0.003864502906799,0.019258742332459,0.01636646270752,0.008915212154388,0.000782597064972,0.354249000549316,TRUE,0 +jbl+AC0-T440p,Sep 23 2020 15:48:30,True,True,100,0.003590517044067,0.019879310131073,0.016916983127594,0.009615495204926,0.000798478126526,0.364127635955811,TRUE,0 +jbl+AC0-T440p,Sep 23 2020 15:49:19,True,True,100,0.003716588020325,0.023860175609589,0.016380727291107,0.009003615379334,0.000774307250977,0.35044002532959,TRUE,0 +jbl+AC0-T440p,Sep 23 2020 16:56:57,True,True,100,0.004425497055054,0.019956090450287,0.017114706039429,0.010911240577698,0.000832149982452,0.336694478988647,TRUE,0 +jbl+AC0-T440p,Sep 23 2020 16:57:23,True,True,100,0.004397692680359,0.021222379207611,0.01826550245285,0.010625832080841,0.000812151432037,0.344640016555786,TRUE,0 +jbl+AC0-T440p,Sep 23 2020 16:57:45,True,True,100,0.004602279663086,0.020297501087189,0.017129955291748,0.010850946903229,0.000865814685822,0.339866161346436,TRUE,0 +jbl+AC0-T440p,Sep 23 2020 16:58:37,True,True,200,0.004463336467743,0.036689649820328,0.025502071380615,0.015932221412659,0.000898872613907,0.681740045547485,TRUE,0 +jbl+AC0-T440p,Sep 23 2020 16:59:37,True,True,200,0.004517335891724,0.036278907060623,0.025654143095017,0.01576028585434,0.000849905014038,0.660790681838989,TRUE,0 +jbl+AC0-T440p,Sep 23 2020 17:14:05,True,False,100,0.006808481216431,0.252511320114136,0.139744215011597,0.111351528167725,0.001188087463379,0.564764976501465,TRUE,0 +jbl+AC0-T440p,Sep 23 2020 17:16:58,True,False,100,0.006502165794373,0.242799952030182,0.137602522373199,0.108403618335724,0.001143708229065,0.556174516677856,TRUE,0 +jbl+AC0-T440p,Sep 24 2020 06:53:53,True,False,100,0.007479875087738,0.252197952270508,0.141312582492828,0.109222292900085,0.001601278781891,0.52592396736145,TRUE,0 +jbl+AC0-T440p,Sep 24 2020 06:56:06,True,False,100,0.020340206623077,1.31586099863052,0.729812262058258,0.577438371181488,0.00078241109848,1.78533124923706,FALSE,0 +jbl+AC0-T440p,Sep 24 2020 07:04:00,True,False,100,0.006233677864075,0.242916750907898,0.135480484962463,0.10392139673233,0.000762076377869,0.569819927215576,TRUE,0 +jbl+AC0-T440p,Sep 24 2020 07:05:19,True,True,100,0.006471273899078,0.023659512996674,0.020732533931732,0.015365273952484,0.000769484043121,0.549034357070923,FALSE,0 +jbl+AC0-T440p,Sep 24 2020 07:05:50,True,True,100,0.005183663368225,0.021180493831635,0.016473467350006,0.010494797229767,0.000771188735962,0.321053028106689,TRUE,0 +jbl+AC0-T440p,Sep 24 2020 07:33:51,True,True,100,0.004018228054047,0.019896368980408,0.024588730335236,0.015463829040527,0.000797684192657,0.375835657119751,TRUE,0 +jbl+AC0-T440p,Oct 08 2020 15:01:01,True,True,100,0.004086337089539,0.022444577217102,1.26581408977509,0.014725821018219,0.002466685771942,0.310548305511475,TRUE,1 +jbl+AC0-T440p,Oct 08 2020 15:25:42,True,True,100,0.004928917884827,0.020494124889374,1.19440255403519,0.01545866727829,0.000807287693024,0.304153442382812,TRUE,1 +jbl+AC0-T440p,Oct 08 2020 15:44:13,True,True,100,0.00410740852356,0.020648219585419,1.24338629007339,0.01569117307663,0.00077033996582,0.33369255065918,TRUE,1 +jbl+AC0-T440p,Oct 08 2020 16:19:05,True,True,100,0.004798595905304,0.022070643901825,1.24563392400742,0.015214123725891,0.000787632465363,0.333659410476685,TRUE,1 +jbl+AC0-T440p,Oct 09 2020 11:23:54,True,True,100,0.004018263816834,0.020824022293091,1.16614150524139,0.015614166259766,0.000755190849304,0.34318208694458,TRUE,1 +jbl+AC0-T440p,Oct 09 2020 11:54:15,True,True,100,0.003045120239258,0.005557940006256,0.009205477237701,0.003398790359497,0.00073746919632,0.356267929077148,TRUE,1 +jbl+AC0-T440p,Oct 09 2020 11:56:19,True,True,100,0.003119325637817,0.005602471828461,0.009082851409912,0.003396863937378,0.000744948387146,0.303446769714356,TRUE,2 +jbl+AC0-T440p,Oct 09 2020 11:58:22,True,True,100,0.003008058071136,0.005401248931885,0.010658957958222,0.003909242153168,0.000718443393707,0.301162958145142,TRUE,3 +jbl+AC0-T440p,Oct 09 2020 11:59:16,True,True,100,0.003015418052673,0.005526115894318,0.010740044116974,0.00400491476059,0.000724492073059,0.313828229904175,TRUE,4 +jbl+AC0-T440p,Oct 09 2020 12:00:32,True,True,100,0.002969658374786,0.005434756278992,0.018136837482452,0.003030817508698,0.000726938247681,0.320115327835083,TRUE,0 +jbl-T440p,Oct 09 2020 12:21:00,True,True,100,0.0034934663772583007,0.0061032938957214355,0.019232537746429443,0.003091294765472412,0.0007375502586364747,0.36986708641052246,N/A diff --git a/djangoldp/tests/settings_default.py b/djangoldp/tests/settings_default.py index 7c7cb1b2b2c41f3eb2f1619ca4f4e6bace9f026b..3686e77775e31fcf1c30567e72db2896ae95c187 100644 --- a/djangoldp/tests/settings_default.py +++ b/djangoldp/tests/settings_default.py @@ -93,4 +93,3 @@ LDP_RDF_CONTEXT={ } SEND_BACKLINKS=False GUARDIAN_AUTO_PREFETCH = True -PERMISSIONS_CACHE = True diff --git a/djangoldp/tests/tests_get.py b/djangoldp/tests/tests_get.py index f2486a1a4612ba330060535012cd28ce66320c57..5e93f212ee7411bb9e1262674a1a4c9b240f8828 100644 --- a/djangoldp/tests/tests_get.py +++ b/djangoldp/tests/tests_get.py @@ -1,3 +1,4 @@ +from djangoldp.serializers import LDListMixin, LDPSerializer from rest_framework.test import APIRequestFactory, APIClient, APITestCase from datetime import datetime from rest_framework.test import APIRequestFactory, APIClient, APITestCase @@ -10,6 +11,8 @@ class TestGET(APITestCase): def setUp(self): self.factory = APIRequestFactory() self.client = APIClient() + LDListMixin.to_representation_cache.invalidate_cache() + LDPSerializer.to_representation_cache.invalidate_cache() def tearDown(self): pass diff --git a/djangoldp/tests/tests_save.py b/djangoldp/tests/tests_save.py index 48fe32f3d91be959db82c26cb8223cdd05d65e21..7a7dbeb3b9059be91bde8ae3127c5a48a6dfa63c 100644 --- a/djangoldp/tests/tests_save.py +++ b/djangoldp/tests/tests_save.py @@ -4,7 +4,7 @@ from rest_framework.test import APIRequestFactory, APIClient from rest_framework.utils import json from djangoldp.models import Model -from djangoldp.serializers import LDPSerializer +from djangoldp.serializers import LDPSerializer, LDListMixin from djangoldp.tests.models import Skill, JobOffer, Invoice, LDPDummy, Resource, Post, Circle, Project @@ -16,6 +16,8 @@ class Save(TestCase): self.user = get_user_model().objects.create_user(username='john', email='jlennon@beatles.com', password='glass onion') self.client.force_authenticate(self.user) + LDListMixin.to_representation_cache.invalidate_cache() + LDPSerializer.to_representation_cache.invalidate_cache() def tearDown(self): pass diff --git a/djangoldp/tests/tests_update.py b/djangoldp/tests/tests_update.py index 134172011e71e4871daaf800c70d86aafcc71d89..ea293c3a4118af7889fcca3224e71e66002b88a7 100644 --- a/djangoldp/tests/tests_update.py +++ b/djangoldp/tests/tests_update.py @@ -4,7 +4,7 @@ from django.test import TestCase from rest_framework.test import APIRequestFactory, APIClient from rest_framework.utils import json -from djangoldp.serializers import LDPSerializer +from djangoldp.serializers import LDPSerializer, LDListMixin from djangoldp.tests.models import Post, UserProfile, Resource, Circle from djangoldp.tests.models import Skill, JobOffer, Conversation, Message, Project @@ -17,6 +17,8 @@ class Update(TestCase): self.user = get_user_model().objects.create_user(username='john', email='jlennon@beatles.com', password='glass onion') self.client.force_authenticate(user=self.user) + LDListMixin.to_representation_cache.invalidate_cache() + LDPSerializer.to_representation_cache.invalidate_cache() def tearDown(self): pass diff --git a/djangoldp/views.py b/djangoldp/views.py index 8112f45aff7c0bffc4f09b492f2eb876fba2a025..af66a19c7ac19a4c0d9cab2043478b8f9e1853a8 100644 --- a/djangoldp/views.py +++ b/djangoldp/views.py @@ -404,6 +404,7 @@ class LDPViewSet(LDPViewSetGenerator): meta_args = {'model': self.model, 'extra_kwargs': { '@id': {'lookup_field': lookup_field}}, 'depth': getattr(self, 'depth', Model.get_meta(self.model, 'depth', 0)), + # 'depth': getattr(self, 'depth', 4), 'extra_fields': self.nested_fields} if self.fields: meta_args['fields'] = self.fields