Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.

Commit a45c8a0

Browse files
committed
fix(account): update accountRecord to specify charset for inEmail
1 parent d2cfe49 commit a45c8a0

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

lib/db/mysql.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -897,20 +897,9 @@ module.exports = function (log, error) {
897897
// verifierSetAt, createdAt, lockedAt, primaryEmail, profileChangedAt
898898
// Where : emails.normalizedEmail = LOWER($1)
899899
//
900-
// There's a newer version of this query named `accountRecord_4`
901-
// which coalesces the `profileChangedAt` column from values in the db.
902-
// We're experiencing unexpectedly bad query performance for reasons
903-
// that we don't yet understand, so we've reverted to using an older
904-
// version of the query while we're figuring that out, and doing the
905-
// coalesce here in code.
906-
// Ref: https://github.com/mozilla/fxa-content-server/issues/6655
907-
var GET_ACCOUNT_RECORD = 'CALL accountRecord_2(?)'
900+
var GET_ACCOUNT_RECORD = 'CALL accountRecord_5(?)'
908901
MySql.prototype.accountRecord = function (email) {
909902
return this.readFirstResult(GET_ACCOUNT_RECORD, [email])
910-
.then(record => {
911-
record.profileChangedAt = record.verifierSetAt || record.createdAt
912-
return record
913-
})
914903
}
915904

916905
// Select : emails

lib/db/schema/patch-091-092.sql

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,38 @@ BEGIN
2929
;
3030
END;
3131

32+
-- Specify the email string encoding for `inEmail`. MySQL fails to use the
33+
-- correct index in subquery if this is not set.
34+
-- Ref: https://github.com/mozilla/fxa-auth-db-mysql/issues/440
35+
CREATE PROCEDURE `accountRecord_5` (
36+
IN `inEmail` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin
37+
)
38+
BEGIN
39+
SELECT
40+
a.uid,
41+
a.email,
42+
a.normalizedEmail,
43+
a.emailVerified,
44+
a.emailCode,
45+
a.kA,
46+
a.wrapWrapKb,
47+
a.verifierVersion,
48+
a.authSalt,
49+
a.verifierSetAt,
50+
a.createdAt,
51+
a.locale,
52+
a.lockedAt,
53+
COALESCE(a.verifierSetAt, a.createdAt) AS profileChangedAt,
54+
e.normalizedEmail AS primaryEmail
55+
FROM
56+
accounts a,
57+
emails e
58+
WHERE
59+
a.uid = (SELECT uid FROM emails WHERE normalizedEmail = LOWER(inEmail))
60+
AND
61+
a.uid = e.uid
62+
AND
63+
e.isPrimary = true;
64+
END;
65+
3266
UPDATE dbMetadata SET value = '92' WHERE name = 'schema-patch-level';

lib/db/schema/patch-092-091.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
-- SET NAMES utf8mb4 COLLATE utf8mb4_bin;
22

33
-- DROP PROCEDURE account_6;
4+
-- DROP PROCEDURE accountRecord_5;
45

56
-- UPDATE dbMetadata SET value = '91' WHERE name = 'schema-patch-level';

0 commit comments

Comments
 (0)