Skip to content

Commit f5cddbf

Browse files
committed
compound index
1 parent 09988c6 commit f5cddbf

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

8.0.0.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ Related pull requests:
2929

3030
## Database Indexes
3131

32-
As part of the email verification and password reset improvements in Parse Server 8, the queries used for these operations have changed to use tokens instead of username/email fields. To ensure optimal query performance, Parse Server now automatically creates indexes on the following fields during server initialization:
32+
As part of the email verification and password reset improvements in Parse Server 8, the queries used for these operations have changed to use tokens instead of username/email fields. To ensure optimal query performance, Parse Server now automatically creates compound indexes on the following fields during server initialization:
3333

34-
- `_User._email_verify_token`: used for email verification queries
35-
- `_User._perishable_token`: used for password reset queries
34+
- `(_email_verify_token, emailVerified, _email_verify_token_expires_at)` - Used for email verification queries
35+
- `(_perishable_token, _perishable_token_expires_at)` - Used for password reset queries
3636

37-
These indexes are created automatically when Parse Server starts, similar to how indexes for `username` and `email` fields are created. No manual intervention is required.
37+
These sparse, compound indexes are created automatically when Parse Server starts. No manual intervention is required.
3838

3939
> [!WARNING]
40-
> If you have a large existing user base, the index creation may take some time during the first server startup after upgrading to Parse Server 8. The server logs will indicate when index creation is complete or if any errors occur. If you have any concerns regarding a potential database performance impact during index creation, you could create these indexes manually in a controlled procedure before upgrading Parse Server.
40+
> If you have a large existing user base, the index creation may take some time during the first server startup after upgrading to Parse Server 8. If you have any concerns regarding a potential database performance impact during index creation, you may create these indexes manually in a controlled manner before upgrading Parse Server.

spec/DatabaseController.spec.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,12 @@ describe('DatabaseController', function () {
413413
case_insensitive_username: { username: 1 },
414414
case_insensitive_email: { email: 1 },
415415
email_1: { email: 1 },
416-
_email_verify_token: { _email_verify_token: 1 },
417-
_perishable_token: { _perishable_token: 1 },
416+
_email_verify_token: {
417+
_email_verify_token: 1,
418+
emailVerified: 1,
419+
_email_verify_token_expires_at: 1,
420+
},
421+
_perishable_token: { _perishable_token: 1, _perishable_token_expires_at: 1 },
418422
});
419423
}
420424
);
@@ -439,8 +443,12 @@ describe('DatabaseController', function () {
439443
_id_: { _id: 1 },
440444
username_1: { username: 1 },
441445
email_1: { email: 1 },
442-
_email_verify_token: { _email_verify_token: 1 },
443-
_perishable_token: { _perishable_token: 1 },
446+
_email_verify_token: {
447+
_email_verify_token: 1,
448+
emailVerified: 1,
449+
_email_verify_token_expires_at: 1,
450+
},
451+
_perishable_token: { _perishable_token: 1, _perishable_token_expires_at: 1 },
444452
});
445453
}
446454
);

src/Controllers/DatabaseController.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,14 +1765,26 @@ class DatabaseController {
17651765
});
17661766

17671767
await this.adapter
1768-
.ensureIndex('_User', requiredUserFields, ['_email_verify_token'], '_email_verify_token', false)
1768+
.ensureIndex(
1769+
'_User',
1770+
requiredUserFields,
1771+
['_email_verify_token', 'emailVerified', '_email_verify_token_expires_at'],
1772+
'_email_verify_token',
1773+
false
1774+
)
17691775
.catch(error => {
17701776
logger.warn('Unable to create index for email verification token: ', error);
17711777
throw error;
17721778
});
17731779

17741780
await this.adapter
1775-
.ensureIndex('_User', requiredUserFields, ['_perishable_token'], '_perishable_token', false)
1781+
.ensureIndex(
1782+
'_User',
1783+
requiredUserFields,
1784+
['_perishable_token', '_perishable_token_expires_at'],
1785+
'_perishable_token',
1786+
false
1787+
)
17761788
.catch(error => {
17771789
logger.warn('Unable to create index for password reset token: ', error);
17781790
throw error;

0 commit comments

Comments
 (0)