diff --git a/server/route/api/v1/shortcut_service.go b/server/route/api/v1/shortcut_service.go index 8732583..578f79d 100644 --- a/server/route/api/v1/shortcut_service.go +++ b/server/route/api/v1/shortcut_service.go @@ -19,6 +19,7 @@ import ( v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1" storepb "github.com/yourselfhosted/slash/proto/gen/store" "github.com/yourselfhosted/slash/server/metric" + "github.com/yourselfhosted/slash/server/service/license" "github.com/yourselfhosted/slash/store" ) @@ -288,10 +289,15 @@ func (s *APIV1Service) GetShortcutAnalytics(ctx context.Context, request *v1pb.G return nil, status.Errorf(codes.NotFound, "shortcut not found") } - activities, err := s.Store.ListActivities(ctx, &store.FindActivity{ + activityFind := &store.FindActivity{ Type: store.ActivityShortcutView, PayloadShortcutID: &shortcut.Id, - }) + } + if !s.LicenseService.IsFeatureEnabled(license.FeatureTypeAdvancedAnalytics) { + createdTsAfter := time.Now().AddDate(0, 0, -14).Unix() + activityFind.CreatedTsAfter = &createdTsAfter + } + activities, err := s.Store.ListActivities(ctx, activityFind) if err != nil { return nil, status.Errorf(codes.Internal, "failed to get activities, err: %v", err) } diff --git a/store/activity.go b/store/activity.go index fecee9e..009dfc7 100644 --- a/store/activity.go +++ b/store/activity.go @@ -59,6 +59,7 @@ type FindActivity struct { Type ActivityType Level ActivityLevel PayloadShortcutID *int32 + CreatedTsAfter *int64 } func (s *Store) CreateActivity(ctx context.Context, create *Activity) (*Activity, error) { diff --git a/store/db/postgres/activity.go b/store/db/postgres/activity.go index cd2c868..64db5dc 100644 --- a/store/db/postgres/activity.go +++ b/store/db/postgres/activity.go @@ -46,6 +46,9 @@ func (d *DB) ListActivities(ctx context.Context, find *store.FindActivity) ([]*s if find.PayloadShortcutID != nil { where, args = append(where, fmt.Sprintf("CAST(payload::JSON->>'shortcutId' AS INTEGER) = %s", placeholder(len(args)+1))), append(args, *find.PayloadShortcutID) } + if find.CreatedTsAfter != nil { + where, args = append(where, "created_ts > "+placeholder(len(args)+1)), append(args, *find.CreatedTsAfter) + } query := ` SELECT diff --git a/store/db/sqlite/activity.go b/store/db/sqlite/activity.go index 76af1e1..0ea59cb 100644 --- a/store/db/sqlite/activity.go +++ b/store/db/sqlite/activity.go @@ -45,6 +45,9 @@ func (d *DB) ListActivities(ctx context.Context, find *store.FindActivity) ([]*s if find.PayloadShortcutID != nil { where, args = append(where, "json_extract(payload, '$.shortcutId') = ?"), append(args, *find.PayloadShortcutID) } + if find.CreatedTsAfter != nil { + where, args = append(where, "created_ts > ?"), append(args, *find.CreatedTsAfter) + } query := ` SELECT