Skip to content

Commit

Permalink
fix(backend): optimize session detail apis and overall loading experi…
Browse files Browse the repository at this point in the history
…ence (#1490)

- sessions are now pre-aggregated into `sessions` table via a materialized view
- improve pagination to be more stable
- better free text matching on sessions
- made everything faster
- refactor & remove unused code

fixes #1467

Signed-off-by: detj <[email protected]>
  • Loading branch information
detj authored Nov 6, 2024
1 parent c4272b8 commit 971c0cb
Show file tree
Hide file tree
Showing 10 changed files with 855 additions and 466 deletions.
8 changes: 0 additions & 8 deletions backend/api/event/plot.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,3 @@ type IssueInstance struct {
Instances *uint64 `json:"instances"`
IssueFreeSessions *float64 `json:"issue_free_sessions"`
}

// SessionInstance represents an entity
// for plotting session instances.
type SessionInstance struct {
DateTime string `json:"datetime"`
Version string `json:"version"`
Instances *uint64 `json:"instances"`
}
70 changes: 67 additions & 3 deletions backend/api/filter/appfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,14 @@ type AppFilter struct {
// keyset pagination.
KeyTimestamp time.Time `form:"key_timestamp"`

// Limit is the count of matching results to
// limit to.
// Limit is the count of matching rows to
// return.
Limit int `form:"limit"`

// Offset if the count of matching rows to
// skip.
Offset int `form:"offset"`

// BiGraph represents if journey plot
// constructions should be bidirectional
// or not.
Expand Down Expand Up @@ -304,12 +308,72 @@ func (af *AppFilter) HasPositiveLimit() bool {
return af.Limit > 0
}

// HasVersions returns true if at least one
// app version is requested.
func (af *AppFilter) HasVersions() bool {
return len(af.Versions) > 0 && len(af.VersionCodes) > 0
}

// HasOSVersions returns true if there at least
// one OS Version is requested.
func (af *AppFilter) HasOSVersions() bool {
return len(af.OsNames) > 0 && len(af.OsVersions) > 0
}

// HasMultiVersions checks if multiple versions
// were requested.
// are requested.
func (af *AppFilter) HasMultiVersions() bool {
return len(af.Versions) > 1 && len(af.VersionCodes) > 1
}

// HasCountries returns true if at least one
// country is requested.
func (af *AppFilter) HasCountries() bool {
return len(af.Countries) > 0
}

// HasNetworkProviders returns true if at least
// one network provider is requested.
func (af *AppFilter) HasNetworkProviders() bool {
return len(af.NetworkProviders) > 0
}

// HasNetworkTypes returns true if at least
// one network type is requested.
func (af *AppFilter) HasNetworkTypes() bool {
return len(af.NetworkTypes) > 0
}

// HasNetworkGenerations returns true if at least
// one network generation is requested.
func (af *AppFilter) HasNetworkGenerations() bool {
return len(af.NetworkGenerations) > 0
}

// HasDeviceLocales returns true if at least
// one device locale is requested.
func (af *AppFilter) HasDeviceLocales() bool {
return len(af.Locales) > 0
}

// HasDeviceManufacturers returns true if at least
// one device manufacturer is requested.
func (af *AppFilter) HasDeviceManufacturers() bool {
return len(af.DeviceManufacturers) > 0
}

// HasDeviceNames returns true if at least
// one device name is requested.
func (af *AppFilter) HasDeviceNames() bool {
return len(af.DeviceNames) > 0
}

// HasTimezone returns true if a timezone
// is requested.
func (af *AppFilter) HasTimezone() bool {
return af.Timezone != ""
}

// LimitAbs returns the absolute value of limit
func (af *AppFilter) LimitAbs() int {
if !af.HasPositiveLimit() {
Expand Down
2 changes: 1 addition & 1 deletion backend/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func main() {
apps.GET(":id/anrGroups/:anrGroupId/plots/journey", measure.GetANRDetailPlotJourney)
apps.GET(":id/sessions", measure.GetSessionsOverview)
apps.GET(":id/sessions/:sessionId", measure.GetSession)
apps.GET(":id/sessions/plots/instances", measure.GetSessionsOverviewPlot)
apps.GET(":id/sessions/plots/instances", measure.GetSessionsOverviewPlotInstances)
apps.GET(":id/alertPrefs", measure.GetAlertPrefs)
apps.PATCH(":id/alertPrefs", measure.UpdateAlertPrefs)
apps.GET(":id/settings", measure.GetAppSettings)
Expand Down
Loading

0 comments on commit 971c0cb

Please sign in to comment.