Skip to content

Commit

Permalink
chore: update find activities
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack committed Aug 13, 2024
1 parent 9876fb2 commit f057cd0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
10 changes: 8 additions & 2 deletions server/route/api/v1/shortcut_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions store/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions store/db/postgres/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions store/db/sqlite/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f057cd0

Please sign in to comment.