mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 02:51:34 +00:00
This commit introduces a new event-driven analytics system to track user interactions with works and translations. The system is designed to be scalable and production-ready. Key changes: - An asynchronous event-driven architecture using `asynq` for handling analytics. - A new background worker process (`cmd/worker`) to process analytics events from a Redis-backed queue. - GraphQL resolvers now publish `AnalyticsEvent`s to the queue instead of directly calling the analytics service. - New `popularTranslations` GraphQL query to leverage the new analytics data. - Integration tests now use `miniredis` to mock Redis, making them self-contained. - The `TODO.md` file has been updated to reflect the completed work.
27 lines
1.2 KiB
Go
27 lines
1.2 KiB
Go
package domain
|
|
|
|
import "context"
|
|
|
|
import "time"
|
|
|
|
type AnalyticsRepository interface {
|
|
IncrementWorkCounter(ctx context.Context, workID uint, field string, value int) error
|
|
IncrementTranslationCounter(ctx context.Context, translationID uint, field string, value int) error
|
|
UpdateWorkStats(ctx context.Context, workID uint, stats WorkStats) error
|
|
UpdateTranslationStats(ctx context.Context, translationID uint, stats TranslationStats) error
|
|
GetOrCreateWorkStats(ctx context.Context, workID uint) (*WorkStats, error)
|
|
GetOrCreateTranslationStats(ctx context.Context, translationID uint) (*TranslationStats, error)
|
|
GetOrCreateUserEngagement(ctx context.Context, userID uint, date time.Time) (*UserEngagement, error)
|
|
UpdateUserEngagement(ctx context.Context, userEngagement *UserEngagement) error
|
|
UpdateTrendingWorks(ctx context.Context, timePeriod string, trending []*Trending) error
|
|
GetTrendingWorks(ctx context.Context, timePeriod string, limit int) ([]*Work, error)
|
|
GetPopularTranslations(ctx context.Context, workID uint, limit int) ([]*Translation, error)
|
|
GetPopularWorks(ctx context.Context, limit int) ([]*PopularWork, error)
|
|
GetWorkViews(ctx context.Context, workID uint) (int, error)
|
|
}
|
|
|
|
type PopularWork struct {
|
|
WorkID uint
|
|
Score float64
|
|
}
|