feat: cache rss feedgen for 5 minutes

The RSS feed should be perfectly fine even when caching them for 5
minutes. This should massively reduce the response times on the
endpoint.

Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
This commit is contained in:
Levente Polyak 2024-08-03 02:54:55 +02:00
parent 33d31d4117
commit a5b94a47f3
No known key found for this signature in database
GPG key ID: FC1B547C8D8172C8
3 changed files with 29 additions and 5 deletions

View file

@ -2,7 +2,8 @@ from fastapi import APIRouter, Request
from fastapi.responses import Response
from feedgen.feed import FeedGenerator
from aurweb import db, filters
from aurweb import config, db, filters
from aurweb.cache import lambda_cache
from aurweb.models import Package, PackageBase
router = APIRouter()
@ -56,9 +57,11 @@ async def rss(request: Request):
)
)
feed = make_rss_feed(request, packages)
response = Response(feed, media_type="application/rss+xml")
# we use redis for caching the results of the feedgen
cache_expire = config.getint("cache", "expiry_time_rss", 300)
feed = lambda_cache("rss", lambda: make_rss_feed(request, packages), cache_expire)
response = Response(feed, media_type="application/rss+xml")
return response
@ -76,7 +79,9 @@ async def rss_modified(request: Request):
)
)
feed = make_rss_feed(request, packages)
response = Response(feed, media_type="application/rss+xml")
# we use redis for caching the results of the feedgen
cache_expire = config.getint("cache", "expiry_time_rss", 300)
feed = lambda_cache("rss_modified", lambda: make_rss_feed(request, packages), cache_expire)
response = Response(feed, media_type="application/rss+xml")
return response