perf: optimize DB connections, queries, and indexes
Fix dev-mode reconnect storm by persisting mongoose connection state on globalThis instead of a module-level flag that resets on Vite HMR. Eliminate redundant in_season DB query on /rezepte — derive seasonal subset from all_brief client-side. Parallelize all page load fetches. Replace N+1 settlement queries in balance route with single batch $in query. Parallelize balance sum and recent splits aggregations. Trim unused dateModified/dateCreated from recipe brief projections. Add indexes: Payment(date, createdAt), PaymentSplit(username), Recipe(short_name), Recipe(season).
This commit is contained in:
@@ -20,8 +20,8 @@ export function briefQueryConfig(recipeLang: string) {
|
||||
prefix: en ? 'translations.en.' : '',
|
||||
/** Projection for brief list queries */
|
||||
projection: en
|
||||
? '_id translations.en short_name images season dateModified icon'
|
||||
: 'name short_name images tags category icon description season dateModified',
|
||||
? '_id translations.en short_name images season icon'
|
||||
: 'name short_name images tags category icon description season',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -45,8 +45,6 @@ export function toBrief(recipe: RecipeModelType, recipeLang: string): BriefRecip
|
||||
icon: recipe.icon,
|
||||
description: en?.description,
|
||||
season: recipe.season || [],
|
||||
dateCreated: recipe.dateCreated,
|
||||
dateModified: recipe.dateModified,
|
||||
germanShortName: recipe.short_name,
|
||||
} as unknown as BriefRecipeType;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user