feat: add Redis caching to cospend API endpoints
All checks were successful
CI / update (push) Successful in 1m21s
All checks were successful
CI / update (push) Successful in 1m21s
Implement comprehensive caching for all cospend routes to improve performance: Cache Implementation: - Balance API: 30-minute TTL for user balances and global balances - Debts API: 15-minute TTL for debt breakdown calculations - Payments List: 10-minute TTL with pagination support - Individual Payment: 30-minute TTL for payment details Cache Invalidation: - Created invalidateCospendCaches() helper function - Invalidates user balances, debts, and payment lists on mutations - Applied to payment create, update, and delete operations - Applied to recurring payment execution (manual and cron)
This commit is contained in:
@@ -5,6 +5,7 @@ import { PaymentSplit } from '../../../../../models/PaymentSplit';
|
||||
import { dbConnect } from '../../../../../utils/db';
|
||||
import { error, json } from '@sveltejs/kit';
|
||||
import { calculateNextExecutionDate } from '../../../../../lib/utils/recurring';
|
||||
import { invalidateCospendCaches } from '$lib/server/cache';
|
||||
|
||||
// This endpoint is designed to be called by a cron job or external scheduler
|
||||
// It processes all recurring payments that are due for execution
|
||||
@@ -65,6 +66,10 @@ export const POST: RequestHandler = async ({ request }) => {
|
||||
|
||||
await Promise.all(splitPromises);
|
||||
|
||||
// Invalidate caches for all affected users
|
||||
const affectedUsernames = recurringPayment.splits.map((split) => split.username);
|
||||
await invalidateCospendCaches(affectedUsernames, payment._id.toString());
|
||||
|
||||
// Calculate next execution date
|
||||
const nextExecutionDate = calculateNextExecutionDate(recurringPayment, now);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user