Cache serialised services in Redis

Same as we’re doing for templates.

This means avoiding a database call, even for services that don’t hit
our API so often.

They’ll still need to go to the database for the API keys, because we’re
not comfortable putting the API key secrets in Redis.

But once a service has got its keys from the database we commit the
transaction, so the connection can be freed up until we need it again to
insert the notification.
This commit is contained in:
Chris Hill-Scott
2020-06-18 15:09:17 +01:00
parent 6c0a4abd52
commit d16d06fdef
2 changed files with 33 additions and 16 deletions

View File

@@ -128,16 +128,17 @@ class SerialisedService(SerialisedModel):
@classmethod
@memory_cache
def from_id(cls, service_id):
return cls(cls.get_dict(service_id))
return cls(cls.get_dict(service_id)['data'])
@staticmethod
@redis_cache.set('service-{service_id}')
def get_dict(service_id):
from app.schemas import service_schema
service_dict = service_schema.dump(dao_fetch_service_by_id(service_id)).data
db.session.commit()
return service_dict
return {'data': service_dict}
@cached_property
def api_keys(self):