Cache resource schemas for a full day
All checks were successful
Tests / test (push) Successful in 23s
All checks were successful
Tests / test (push) Successful in 23s
This commit is contained in:
parent
70acf2c381
commit
83533129bd
1 changed files with 9 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
|||
import kubernetes
|
||||
from django.core.cache import cache
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models
|
||||
from django.utils.functional import cached_property
|
||||
|
@ -334,10 +335,17 @@ class ServiceOfferingControlPlane(models.Model):
|
|||
|
||||
@cached_property
|
||||
def resource_schema(self):
|
||||
cache_key = f"servala:crd:schema:{self.pk}"
|
||||
if result := cache.get(cache_key):
|
||||
return result
|
||||
|
||||
version = self.service_definition.api_definition["version"]
|
||||
for v in self.resource_definition.spec.versions:
|
||||
if v.name == version:
|
||||
return v.schema.open_apiv3_schema.to_dict()
|
||||
result = v.schema.open_apiv3_schema.to_dict()
|
||||
timeout_seconds = 60 * 60 * 24
|
||||
cache.set(cache_key, result, timeout=timeout_seconds)
|
||||
return result
|
||||
|
||||
@cached_property
|
||||
def django_model(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue