mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 05:37:19 +01:00
refactor(money): eliminate redundant getActiveSubscriptions query
The money page fetched active subs and all subs separately — 2 DB queries for data that's a strict subset. Now fetches getAllSubscriptions once and filters active in memory. Removes getActiveSubscriptions from the query layer entirely. Also drops dead getCurrentUserId() from session.ts (deprecated, had zero callers). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
85a2803aa9
commit
98e88b6516
3 files changed
+2
-24
No files matched your search
@@ -7,7 +7,6 @@ import { CancelledSubsSection } from "@/components/money/CancelledSubsSection";
|
||||
import { SUBSCRIPTION_META, FREQUENCY } from "@/config/subscriptions";
|
||||
import { SUB_STATUS, type SubStatus } from "@/lib/constants/statuses";
|
||||
import {
|
||||
getActiveSubscriptions,
|
||||
getAllSubscriptions,
|
||||
getFinancialCommitments,
|
||||
calculateMonthlyBurn,
|
||||
@@ -86,11 +85,11 @@ function SubRow({ sub }: { sub: Awaited<ReturnType<typeof getAllSubscriptions>>[
|
||||
|
||||
export default async function MoneyPage() {
|
||||
const userId = await requirePageUserId();
|
||||
const [activeSubs, allSubs, commitments] = await Promise.all([
|
||||
getActiveSubscriptions(userId),
|
||||
const [allSubs, commitments] = await Promise.all([
|
||||
getAllSubscriptions(userId),
|
||||
getFinancialCommitments(userId),
|
||||
]);
|
||||
const activeSubs = allSubs.filter((s) => s.status === SUB_STATUS.ACTIVE);
|
||||
const burn = calculateMonthlyBurn(activeSubs);
|
||||
const visibleSubs = allSubs.filter((s) => s.status !== SUB_STATUS.CANCELLED);
|
||||
const cancelledSubs = allSubs.filter((s) => s.status === SUB_STATUS.CANCELLED);
|
||||
|
||||
@@ -90,19 +90,6 @@ export async function deleteSubscription(userId: string, id: string) {
|
||||
return deleted ?? null;
|
||||
}
|
||||
|
||||
export async function getActiveSubscriptions(userId: string) {
|
||||
return db
|
||||
.select()
|
||||
.from(subscriptions)
|
||||
.where(
|
||||
and(
|
||||
eq(subscriptions.userId, userId),
|
||||
eq(subscriptions.status, SUB_STATUS.ACTIVE),
|
||||
),
|
||||
)
|
||||
.orderBy(sql`${subscriptions.amount} DESC NULLS LAST`);
|
||||
}
|
||||
|
||||
export async function getAllSubscriptions(userId: string) {
|
||||
return db
|
||||
.select()
|
||||
|
||||
@@ -61,11 +61,3 @@ export async function getApiUserId(): Promise<string | null> {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use requirePageUserId() in server components/actions,
|
||||
* or getSessionUserId() + 401 check in API routes.
|
||||
*/
|
||||
export async function getCurrentUserId(): Promise<string> {
|
||||
return requirePageUserId();
|
||||
}
|
||||
Reference in new issue
Block a user