Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
Revert "[Admin Analytics] add fetcher tests" (#39287)
Browse files Browse the repository at this point in the history
  • Loading branch information
novoselrok authored and mohammadualam committed Jul 22, 2022
1 parent b883e37 commit 8cf5aa1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 322 deletions.
30 changes: 10 additions & 20 deletions internal/adminanalytics/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type AnalyticsFetcher struct {
nodesQuery *sqlf.Query
summaryQuery *sqlf.Query
cache bool
noSetCache *bool
}

type AnalyticsNodeData struct {
Expand Down Expand Up @@ -66,7 +65,11 @@ func (f *AnalyticsFetcher) Nodes(ctx context.Context) ([]*AnalyticsNode, error)
nodes = append(nodes, &AnalyticsNode{data})
}

now := bod(time.Now())
if _, err := setArrayToCache(cacheKey, nodes); err != nil {
return nil, err
}

now := time.Now()
to := now
daysOffset := 1
from, err := getFromDate(f.dateRange, now)
Expand All @@ -75,7 +78,7 @@ func (f *AnalyticsFetcher) Nodes(ctx context.Context) ([]*AnalyticsNode, error)
}

if f.dateRange == "LAST_THREE_MONTHS" {
to = sow(now)
to = now.AddDate(0, 0, -int(now.Weekday())+1) // monday of current week
daysOffset = 7
}

Expand All @@ -85,7 +88,7 @@ func (f *AnalyticsFetcher) Nodes(ctx context.Context) ([]*AnalyticsNode, error)
var node *AnalyticsNode

for _, n := range nodes {
if date.Equal(bod(n.Data.Date)) {
if bod(date).Equal(bod(n.Data.Date)) {
node = n
break
}
Expand All @@ -105,26 +108,15 @@ func (f *AnalyticsFetcher) Nodes(ctx context.Context) ([]*AnalyticsNode, error)
allNodes = append(allNodes, node)
}

if f.noSetCache == nil || *f.noSetCache != true {
if _, err := setArrayToCache(cacheKey, allNodes); err != nil {

This comment has been minimized.

Copy link
@thenamankumar

thenamankumar Jul 23, 2022

Member

This also resolved the caching bug. I missed mentioning the fix in the PR. I'll add this back separately.

return nil, err
}
}

return allNodes, nil

}

// beginning of day
func bod(t time.Time) time.Time {
year, month, day := t.Date()
return time.Date(year, month, day, 0, 0, 0, 0, t.Location())
}

// start of week (monday)
func sow(t time.Time) time.Time {
return t.AddDate(0, 0, -int(t.Weekday())+1)
}

type AnalyticsSummaryData struct {
TotalCount float64
TotalUniqueUsers float64
Expand Down Expand Up @@ -157,10 +149,8 @@ func (f *AnalyticsFetcher) Summary(ctx context.Context) (*AnalyticsSummary, erro

summary := &AnalyticsSummary{data}

if f.noSetCache == nil || *f.noSetCache != true {
if _, err := setItemToCache(cacheKey, summary); err != nil {
return nil, err
}
if _, err := setItemToCache(cacheKey, summary); err != nil {
return nil, err
}

return summary, nil
Expand Down
8 changes: 3 additions & 5 deletions internal/adminanalytics/notebooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import (
)

type Notebooks struct {
DateRange string
DB database.DB
Cache bool
NoSetCache *bool
DateRange string
DB database.DB
Cache bool
}

func (s *Notebooks) Creations() (*AnalyticsFetcher, error) {
Expand All @@ -26,7 +25,6 @@ func (s *Notebooks) Creations() (*AnalyticsFetcher, error) {
summaryQuery: summaryQuery,
group: "Notebooks:Creations",
cache: s.Cache,
noSetCache: s.NoSetCache,
}, nil
}

Expand Down
297 changes: 0 additions & 297 deletions internal/adminanalytics/notebooks_test.go

This file was deleted.

0 comments on commit 8cf5aa1

Please sign in to comment.