mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-19 22:14:12 -04:00
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:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user