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:
@@ -193,6 +193,8 @@ const RecipeSchema = new mongoose.Schema(
|
||||
);
|
||||
|
||||
// Indexes for efficient querying
|
||||
RecipeSchema.index({ short_name: 1 });
|
||||
RecipeSchema.index({ season: 1 });
|
||||
RecipeSchema.index({ "translations.en.short_name": 1 });
|
||||
RecipeSchema.index({ "translations.en.translationStatus": 1 });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user