Implement deadline matching logic for dashboard repository and enhance unit tests
- Added the `deadlineWithinWindowMatch` function to match raw deadline fields stored as Unix seconds or milliseconds, ensuring accurate filtering in MongoDB queries. - Updated the `ClosingSoon` method in the repository to utilize the new deadline matching logic, improving query accuracy for upcoming deadlines. - Introduced a new unit test, `TestDeadlineWithinWindowMatchCoversSecondsAndMilliseconds`, to validate the functionality of the deadline matching logic, ensuring both seconds and milliseconds are correctly handled. - Enhanced comments in the `widget_cache` and `search_list_cache` files for better clarity on cache behavior and staleness. This update improves the accuracy of deadline handling in the dashboard service and strengthens the test coverage for related functionalities.
This commit is contained in:
@@ -14,7 +14,11 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
widgetCacheTTL = 60 * time.Second
|
||||
// widgetCacheTTL is the fresh window before a background reload is triggered.
|
||||
widgetCacheTTL = 60 * time.Second
|
||||
// widgetStaleGraceTTL is how long stale entries may be served while reloading.
|
||||
// Dashboard widgets have no write-side invalidation; expect up to this lag after
|
||||
// data changes (e.g. a new tender may not appear in cached widgets immediately).
|
||||
widgetStaleGraceTTL = 5 * time.Minute
|
||||
widgetReloadTimeout = 2 * time.Minute
|
||||
)
|
||||
@@ -46,6 +50,8 @@ func newWidgetCache[T any](redisClient redis.Client, log logger.Logger, keyPrefi
|
||||
func (c *widgetCache[T]) Get(ctx context.Context, key string, load widgetLoader[T]) (T, error) {
|
||||
var zero T
|
||||
|
||||
// Returned values are shared across concurrent callers via singleflight and stale
|
||||
// hits. Callers must treat them as read-only through JSON serialization.
|
||||
if value, ok := c.fresh(key); ok {
|
||||
return value, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user