add caching

This commit is contained in:
Fran Jurmanović
2025-05-28 19:59:43 +02:00
parent 0ced45ce55
commit 3dfbe77219
8 changed files with 382 additions and 73 deletions

View File

@@ -2,6 +2,7 @@ package service
import (
"acc-server-manager/local/repository"
"context"
"log"
"go.uber.org/dig"
@@ -21,11 +22,18 @@ func InitializeServices(c *dig.Container) {
c.Provide(NewConfigService)
c.Provide(NewLookupService)
err := c.Invoke(func(server *ServerService, api *ApiService, config *ConfigService) {
err := c.Invoke(func(server *ServerService, api *ApiService, config *ConfigService, lookup *LookupService) {
api.SetServerService(server)
config.SetServerService(server)
// Initialize lookup data using repository directly
lookup.cache.Set("tracks", lookup.repository.GetTracks(context.Background()))
lookup.cache.Set("cars", lookup.repository.GetCarModels(context.Background()))
lookup.cache.Set("drivers", lookup.repository.GetDriverCategories(context.Background()))
lookup.cache.Set("cups", lookup.repository.GetCupCategories(context.Background()))
lookup.cache.Set("sessions", lookup.repository.GetSessionTypes(context.Background()))
})
if err != nil {
log.Panic("unable to initialize server service in api service")
log.Panic("unable to initialize services:", err)
}
}