Skip to content

Commit

Permalink
perf(metadata): enabling client-side caching
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Sep 30, 2023
1 parent 5008c8e commit 0dc07b5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions cmd/fibr/fibr.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ func main() {
os.Exit(1)
}

services, err := newServices(config, clients, adapters)
endCtx := clients.health.End(ctx)

services, err := newServices(endCtx, config, clients, adapters)
if err != nil {
slog.Error("services", "err", err)
os.Exit(1)
}

ports := newPorts(config, clients, services)

endCtx := clients.health.End(ctx)

stopOnDone := Starters{services.amqpThumbnail, services.amqpExif, services.sanitizer}
stopOnDone.Start(clients.health.Done(ctx))
defer stopOnDone.GracefulWait()
Expand Down
6 changes: 4 additions & 2 deletions cmd/fibr/service.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"context"

"github.com/ViBiOh/fibr/pkg/crud"
"github.com/ViBiOh/fibr/pkg/fibr"
"github.com/ViBiOh/fibr/pkg/metadata"
Expand All @@ -26,7 +28,7 @@ type services struct {
thumbnail thumbnail.Service
}

func newServices(config configuration, clients client, adapters adapters) (services, error) {
func newServices(ctx context.Context, config configuration, clients client, adapters adapters) (services, error) {
thumbnailService, err := thumbnail.New(config.thumbnail, adapters.storage, clients.redis, clients.telemetry.MeterProvider(), clients.telemetry.TracerProvider(), clients.amqp)
if err != nil {
return services{}, err
Expand All @@ -37,7 +39,7 @@ func newServices(config configuration, clients client, adapters adapters) (servi
return services{}, err
}

metadataService, err := metadata.New(config.metadata, adapters.storage, clients.telemetry.MeterProvider(), clients.telemetry.TracerProvider(), clients.amqp, clients.redis, adapters.exclusiveService)
metadataService, err := metadata.New(ctx, config.metadata, adapters.storage, clients.telemetry.MeterProvider(), clients.telemetry.TracerProvider(), clients.amqp, clients.redis, adapters.exclusiveService)
if err != nil {
return services{}, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/metadata/exif.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func Flags(fs *flag.FlagSet, prefix string) *Config {
return &config
}

func New(config *Config, storageService absto.Storage, meterProvider metric.MeterProvider, traceProvider trace.TracerProvider, amqpClient *amqpclient.Client, redisClient redis.Client, exclusiveService exclusive.Service) (Service, error) {
func New(ctx context.Context, config *Config, storageService absto.Storage, meterProvider metric.MeterProvider, traceProvider trace.TracerProvider, amqpClient *amqpclient.Client, redisClient redis.Client, exclusiveService exclusive.Service) (Service, error) {
var amqpExchange string

if amqpClient != nil {
Expand Down Expand Up @@ -127,15 +127,15 @@ func New(config *Config, storageService absto.Storage, meterProvider metric.Mete
}

return service.loadExif(ctx, item)
}, traceProvider).WithMaxConcurrency(provider.MaxConcurrency)
}, traceProvider).WithMaxConcurrency(provider.MaxConcurrency).WithClientSideCaching(ctx, "fibr_exif")

service.aggregateCache = cache.New(redisClient, redisKey, func(ctx context.Context, item absto.Item) (provider.Aggregate, error) {
if !item.IsDir() {
return provider.Aggregate{}, errInvalidItemType
}

return service.loadAggregate(ctx, item)
}, traceProvider).WithMaxConcurrency(provider.MaxConcurrency)
}, traceProvider).WithMaxConcurrency(provider.MaxConcurrency).WithClientSideCaching(ctx, "fibr_aggregate")

return service, nil
}
Expand Down

0 comments on commit 0dc07b5

Please sign in to comment.