-
Notifications
You must be signed in to change notification settings - Fork 83
Code issue to claim distribution stat #1675
Conversation
/retest |
/hold |
@@ -447,7 +447,7 @@ func TestStatDates(t *testing.T) { | |||
db, _ := testDatabaseInstance.NewDatabase(t, nil) | |||
realm := NewRealmWithDefaults("Test Realm") | |||
|
|||
now := time.Now() | |||
now := time.Now().UTC() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a bug. This test fails in the evening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. I've hit a few of those when I run tests late at night too.
pkg/database/token.go
Outdated
} | ||
} | ||
|
||
// updateStatsCodeClaimed updates the statistics, increasing the number of codes | ||
// claimed. | ||
func (db *Database) updateStatsCodeClaimed(t time.Time, authApp *AuthorizedApp) { | ||
t = timeutils.UTCMidnight(t) | ||
func (db *Database) updateStatsCodeClaimed(t time.Time, authApp *AuthorizedApp, vc *VerificationCode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this function could be simplified by updating the two stats independently, potentially even updating CodeClaimDistribution in another function.
Similarly, this will be faster and less error-prone to do it in straight SQL:
WITH arr AS (
-- this is the fun part. you could build this with case statements or use a
-- range function: https://www.postgresql.org/docs/9.3/rangetypes.html
)
INSERT INTO realm_stats(date, realm_id, code_claim_distribution
VALUES ($1, $2, arr)
ON CONFLICT (date, realm_id) DO UPDATE
SET code_claim_distribution = array_agg(UNNEST(arr) + UNNEST(realm_stats.code_claim_distribution))
/hold cancel |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: sethvargo, whaught The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Issue #1231
Proposed Changes
Release Note