model_extra.go
917 Bytes
-
✨ feat: enhance soft-delete handling & boost pricing cache performance · d7428227Summary ------- This commit unifies soft-delete behaviour across meta tables and introduces an in-memory cache for model pricing look-ups to improve throughput under high concurrency. Details ------- Soft-delete consistency • PrefillGroup / Vendor / Model – Added `gorm.DeletedAt` field with `json:"-" gorm:"index"`. – Replaced plain `uniqueIndex` with partial unique indexes `uniqueIndex:<name>,where:deleted_at IS NULL` allowing duplicate keys after logical deletion while preserving uniqueness for active rows. • Imports updated to include `gorm.io/gorm`. • JSON output now hides `deleted_at`, matching existing tables. High-throughput pricing cache • model/pricing.go – Added thread-safe maps `modelEnableGroups` & `modelQuotaTypeMap` plus RW-mutex for O(1) access. – `updatePricing()` now refreshes these maps alongside `pricingMap`. • model/model_extra.go – Rewrote `GetModelEnableGroups` & `GetModelQuotaType` to read from the new maps, falling back to automatic refresh via `GetPricing()`. Misc • Retained `RefreshPricing()` helper for immediate cache invalidation after admin actions. • All modified files pass linter; no breaking DB migrations required (handled by AutoMigrate). Result ------ – Soft-delete logic is transparent, safe, and allows record “revival”. – Pricing-related queries are now constant-time, reducing CPU usage and latency under load.t0ng7u committed