Cache more forgejo-authentication source queries #172
3 changed files with 16 additions and 3 deletions
10
CHANGELOG.md
10
CHANGELOG.md
|
|
@ -1,3 +1,13 @@
|
||||||
|
# 5.2.1 (2025-11-26)
|
||||||
|
|
||||||
|
## Changes
|
||||||
|
|
||||||
|
- Improve caching in Forgejo authentication sources. All calls to a
|
||||||
|
Forgejo-authentication source are now cached with expiration duration
|
||||||
|
between one and five minutes. Authentication-related changes in Forgejo
|
||||||
|
instances might therefore become visible after up to five minutes.
|
||||||
|
|
||||||
|
|
||||||
# 5.2.0 (2025-10-29)
|
# 5.2.0 (2025-10-29)
|
||||||
|
|
||||||
## New features
|
## New features
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
__version__ = '5.2.0'
|
__version__ = '5.2.1'
|
||||||
|
|
|
||||||
|
|
@ -43,9 +43,9 @@ class MethodCache:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def cache_temporary(
|
def cache_temporary(
|
||||||
duration: int = 3600,
|
duration: int = 300,
|
||||||
) -> Callable:
|
) -> Callable:
|
||||||
""" Cache results for a given time (default: 3600 seconds) """
|
""" Cache results for a given time (default: 300 seconds) """
|
||||||
def decorator(func: Callable) -> Callable:
|
def decorator(func: Callable) -> Callable:
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
|
|
@ -132,6 +132,7 @@ class ForgejoAuthenticationSource(AuthenticationSource, MethodCache):
|
||||||
raise InvalidTokenError(msg)
|
raise InvalidTokenError(msg)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
@MethodCache.cache_temporary(duration=120)
|
||||||
def _get_user(
|
def _get_user(
|
||||||
self,
|
self,
|
||||||
token: str,
|
token: str,
|
||||||
|
|
@ -145,6 +146,7 @@ class ForgejoAuthenticationSource(AuthenticationSource, MethodCache):
|
||||||
token,
|
token,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@MethodCache.cache_temporary(duration=120)
|
||||||
def _get_teams_for_user(self, token: str) -> dict:
|
def _get_teams_for_user(self, token: str) -> dict:
|
||||||
r = self._get_json_from_endpoint('user/teams', token)
|
r = self._get_json_from_endpoint('user/teams', token)
|
||||||
return {team['name']: team for team in r}
|
return {team['name']: team for team in r}
|
||||||
|
|
@ -208,6 +210,7 @@ class ForgejoAuthenticationSource(AuthenticationSource, MethodCache):
|
||||||
)
|
)
|
||||||
return permissions
|
return permissions
|
||||||
|
|
||||||
|
@MethodCache.cache_temporary(duration=60)
|
||||||
def authenticate(
|
def authenticate(
|
||||||
self,
|
self,
|
||||||
token: str,
|
token: str,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue