Summary
`LibraryConfigurationMiddleware` does a DB round-trip on every single request to resolve the tenant, and continues the pipeline even when the library can't be resolved.
Details
`LibraryConfigurationMiddleware.Invoke` (src/Inshapardaz.Api/Infrastructure/Middleware/LibraryConfigurationMiddleware.cs:31-43) calls `_libraryRepository.GetLibraryById(libraryId, ...)` unconditionally, and when `library is null` it just logs a warning and calls `next(context)` anyway, leaving `LibraryConfiguration` unconfigured rather than failing the request.
Impact
- Extra DB hit on every request for data that changes rarely.
- Given this is the linchpin of the multi-tenant model, silently continuing with a stale/default/unconfigured `LibraryConfiguration` when the library can't be resolved is a soft-fail-open design that's riskier than failing closed (404).
Suggested fix
Cache library configuration (invalidate on library update), and return 404 early when the library can't be resolved instead of continuing the pipeline.
Summary
`LibraryConfigurationMiddleware` does a DB round-trip on every single request to resolve the tenant, and continues the pipeline even when the library can't be resolved.
Details
`LibraryConfigurationMiddleware.Invoke` (src/Inshapardaz.Api/Infrastructure/Middleware/LibraryConfigurationMiddleware.cs:31-43) calls `_libraryRepository.GetLibraryById(libraryId, ...)` unconditionally, and when `library is null` it just logs a warning and calls `next(context)` anyway, leaving `LibraryConfiguration` unconfigured rather than failing the request.
Impact
Suggested fix
Cache library configuration (invalidate on library update), and return 404 early when the library can't be resolved instead of continuing the pipeline.