Skip to content

Commit

Permalink
better MAU detection
Browse files Browse the repository at this point in the history
  • Loading branch information
radiantspace committed May 19, 2024
1 parent 78dee79 commit a648e55
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion backend/app/db/mongo/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,11 @@ func (c *Client) GetUserIdsUsedSince(ctx context.Context, since time.Time, page
findOptions := options.Find()
findOptions.SetSkip(int64(page * pageSize))
findOptions.SetLimit(int64(pageSize))
cursor, err := collection.Find(ctx, bson.M{"last_used_at": bson.M{"$gte": since.Format("2006-01-02T15:04:05")}}, findOptions)
// last_used_at or subscription_date is gte than since
cursor, err := collection.Find(ctx, bson.M{"$or": []bson.M{
{"last_used_at": bson.M{"$gte": since.Format("2006-01-02T15:04:05")}},
{"subscription_date": bson.M{"$gte": since.Format("2006-01-02")}},
}}, findOptions)
if err != nil {
return nil, fmt.Errorf("GetUserIdsSince: failed to find users: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions backend/app/status/system_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ func (h *SystemStatusHandler) GetSystemStatus() SystemStatus {
basicUsers, _ := h.MongoDB.GetUsersCountForSubscription(context.Background(), "basic")
status.Usage.TotalBasicUsers = basicUsers

weekActiveUsers, _ := h.MongoDB.GetUserIdsUsedSince(context.Background(), time.Now().AddDate(0, 0, -7), 0, 1000000)
weekActiveUsers, _ := h.MongoDB.GetUserIdsUsedSince(context.Background(), time.Now().UTC().AddDate(0, 0, -7), 0, 1000000)
status.Usage.WeekActiveUsers = int64(len(weekActiveUsers))

monthActiveUsers, _ := h.MongoDB.GetUserIdsUsedSince(context.Background(), time.Now().AddDate(0, -1, 0), 0, 1000000)
monthActiveUsers, _ := h.MongoDB.GetUserIdsUsedSince(context.Background(), time.Now().UTC().AddDate(0, -1, 0), 0, 1000000)
status.Usage.MonthActiveUsers = int64(len(monthActiveUsers))
}
return status
Expand Down

0 comments on commit a648e55

Please sign in to comment.