Don’t do multiple get API calls when revoking

It’s redundant to make two API calls here, one to get all keys and one
to get a single key. Since the API calls are sequential we can speed
things up by getting the one key from the list of all keys.
This commit is contained in:
Chris Hill-Scott
2018-11-07 11:53:29 +00:00
parent d1c9dcfb1d
commit 591bbe9a49
5 changed files with 33 additions and 19 deletions

View File

@@ -1,3 +1,4 @@
from flask import abort
from notifications_utils.field import Field
from werkzeug.utils import cached_property
@@ -344,3 +345,9 @@ class Service():
@property
def api_key_names(self):
return [key['name'] for key in self.api_keys]
def get_api_key(self, id):
try:
return next(key for key in self.api_keys if key['id'] == id)
except StopIteration:
abort(404)