Sitelet https://web.archive.org/web/20210903212051/https://github.com/meteor/meteor/issues/11382
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PERFORMANCE] - Make email a low case string and amend/simplify searches in the Users collection #11382

Open
paulincai opened this issue Apr 10, 2021 · 11 comments · May be fixed by #11419
Open

[PERFORMANCE] - Make email a low case string and amend/simplify searches in the Users collection #11382

paulincai opened this issue Apr 10, 2021 · 11 comments · May be fixed by #11419

Comments

@paulincai
Copy link
Contributor

@paulincai paulincai commented Apr 10, 2021

I am really sorry if this was discussed already in the form of an issue. I was supposed to raise this one a couple of months back and got disconnected from business for a while.

The issue is explained at this link:
https://forums.meteor.com/t/slow-mongo-query-on-createuser/54879

"
My app has about 400K users, and this query can take up to 6000ms (especially when the email address starts with a common first name).
"

@StorytellerCZ
Copy link
Contributor

@StorytellerCZ StorytellerCZ commented Apr 23, 2021

@paulincai What is the proposed solution here? From what I have seen on the forums, using collation seemed to be favored, but the downside I see there is that you need to define a locale which might create some interesting edge cases. I'm all for improving the search script, but please bear in mind that the local-part of the e-mail can be case sensitive as per RFC5321.

@paulincai
Copy link
Contributor Author

@paulincai paulincai commented Apr 23, 2021

@StorytellerCZ
Given the fact that the matter is standardized but also subject to preference / opinion by some large email providers, I think this is more about what I feel than what I think :).
The practical questions I see are:

  • is Paul@gMail.com and paul@gmail.com two different entities/people/recipients?
  • is there any benefit in capitalizing an email address (from the system provider perspective and user perspective).

In the example below I am logging in to my Yahoo with an existing address and I am being matched to a lower case address.

Screen Shot 2021-04-23 at 14 11 06
Screen Shot 2021-04-23 at 14 11 15

In the example below, which is my recommendation for our subject in discussion here, I trying to create a mixed case address and I am being provided with a lower case address.

Screen Shot 2021-04-23 at 14 15 22
Screen Shot 2021-04-23 at 14 16 30

We could let the user type in a mixed case address and, like Yahoo, convert to lower case before saving to DB. This could be done in two ways:

  • make Meteor only accept lower case addresses and inform the developer about it with some error.
  • make this a Developer decision and give an option to the Developer to only search with a lower case algorithm. (this is my favorite.)

@StorytellerCZ
Copy link
Contributor

@StorytellerCZ StorytellerCZ commented Apr 23, 2021

Domain is always lowercase, the problem is with the local-part:

   Local-part     = Dot-string / Quoted-string
                  ; MAY be case-sensitive

That major providers automatically lowercase them is all nice and dandy, but this needs to work for everyone. I'm for optimizing and improving the search, but I'm against disregarding the standard which will only result into a bug report down the line that will demand that Meteor Accounts follow RFC5321.

@paulincai
Copy link
Contributor Author

@paulincai paulincai commented Apr 23, 2021

ok, that is understandable. In this case perhaps we can leave it to the developer/app owner to decide on how she wants to handle emails. Meteor stays compliant (base tech level), I fine tune my performance (app owner tech level / overlay) perhaps via Accounts.config({ useLowerCaseEmails: true }) ....with a better key naming :) which calls a different search function in the Accounts.

As far as improving the case sensitive search is concerned, I am completely clueless whether the actual setup with selectorForFastCaseInsensitiveLookup and generateCasePermutationsForString can be outperformed by a different algorithm.

@tjramage
Copy link

@tjramage tjramage commented Apr 23, 2021

@paulincai – Totally agree that leaving up to the developer makes sense here. We run a B2B SaaS service that has thousands of users and we enforce lowercase emails throughout the system. No one has ever complained and we haven't had any issues over our several years of operation.

@ritwik1233
Copy link
Contributor

@ritwik1233 ritwik1233 commented May 10, 2021

Hi, I am new to open source.

I created a Pull Request which implements the above-proposed solution.

Thanks

@StorytellerCZ StorytellerCZ linked a pull request that will close this issue May 11, 2021
@StorytellerCZ
Copy link
Contributor

@StorytellerCZ StorytellerCZ commented May 11, 2021

@ritwik1233 Thanks a lot! We will take a look at it and if everything checks out (which I think it does) we will get it out by the next Meteor release.

@ritwik1233
Copy link
Contributor

@ritwik1233 ritwik1233 commented May 11, 2021

@StorytellerCZ StorytellerCZ added this to the Release 2.4 milestone Jun 14, 2021
@StorytellerCZ StorytellerCZ removed this from the Release 2.4 milestone Jul 28, 2021
@StorytellerCZ StorytellerCZ added this to the Release 2.5 milestone Jul 28, 2021
@StorytellerCZ
Copy link
Contributor

@StorytellerCZ StorytellerCZ commented Jul 28, 2021 •

Please test the proposed PR #11419 and let us know what impact it had so that we can move forward with releasing or improving it.

@StorytellerCZ
Copy link
Contributor

@StorytellerCZ StorytellerCZ commented Aug 17, 2021

@paulincai did you get a chance to test the PR?

@paulincai
Copy link
Contributor Author

@paulincai paulincai commented Aug 18, 2021

Hi @StorytellerCZ to be frank I didn't even know this was expected of me. Following a conversation in the Forum I took the liberty to speak on behalf of those participants and raised the ticket :). Anyway, now that you appointed me on this one, let's look at it...

I used the files you provided here https://gist.github.com/zodern/4ad546b9ddc2cf780fed476c85c1f053 and modified them to use in a Meteor project. A small repo here based on create app --react: https://github.com/paulincai/test_users/tree/main/server
There are 2 files under the 'server' folder and true/false flags to create the users and to run one query or the other.

My results look like this (observe Searching, found and Spent. Unlike the initial files which traverse the entire DB (having a '+ x' at the end of the searched email), I am actually searching for the right addresses and find them):

When searching for the exact address, like would be the case when users can only save addresses in small caps, the time is constantly 1-2ms.

I20210818-12:42:26.877(4)? Searching:  QDGI-sQ0tm5LRw1@domain.com
I20210818-12:42:29.756(4)? found:  QDGI-sQ0tm5LRw1@domain.com
I20210818-12:42:29.759(4)? Spent 2879ms for Case Insensitive Regexp
I20210818-12:42:29.759(4)? Searching:  UCKV-gSayggxf3o@domain.com
I20210818-12:42:32.610(4)? found:  UCKV-gSayggxf3o@domain.com
I20210818-12:42:32.610(4)? Spent 2854ms for Case Insensitive Regexp
I20210818-12:42:32.610(4)? Searching:  0kql-8CDF7cOkZq@domain.com
I20210818-12:42:35.542(4)? found:  0kql-8CDF7cOkZq@domain.com
I20210818-12:42:35.542(4)? Spent 2933ms for Case Insensitive Regexp
I20210818-12:42:35.543(4)? Searching:  zqI8-dQzETMOhS4@domain.com
I20210818-12:42:38.482(4)? found:  zqI8-dQzETMOhS4@domain.com
I20210818-12:42:38.482(4)? Spent 2940ms for Case Insensitive Regexp
I20210818-12:42:38.482(4)? Searching:  gzgB-wPQVNUPJMn@domain.com
I20210818-12:42:41.355(4)? found:  gzgB-wPQVNUPJMn@domain.com
I20210818-12:42:41.356(4)? Spent 2873ms for Case Insensitive Regexp
I20210818-12:42:41.356(4)? Searching:  cqU9-nD8IFdBqYa@domain.com
I20210818-12:42:44.210(4)? found:  cqU9-nD8IFdBqYa@domain.com
I20210818-12:42:44.210(4)? Spent 2855ms for Case Insensitive Regexp
I20210818-12:42:44.211(4)? Searching:  CDue-JOwXAwyGNT@domain.com
I20210818-12:42:47.145(4)? found:  CDue-JOwXAwyGNT@domain.com
I20210818-12:42:47.146(4)? Spent 2935ms for Case Insensitive Regexp
I20210818-12:42:47.146(4)? Searching:  i1UE-TZS8RcKblT@domain.com
I20210818-12:42:50.095(4)? found:  i1UE-TZS8RcKblT@domain.com
I20210818-12:42:50.095(4)? Spent 2950ms for Case Insensitive Regexp
I20210818-12:42:50.095(4)? Searching:  QGWX-YmR8l9pMnZ@domain.com
I20210818-12:42:53.050(4)? found:  QGWX-YmR8l9pMnZ@domain.com
I20210818-12:42:53.050(4)? Spent 2955ms for Case Insensitive Regexp
I20210818-12:42:53.050(4)? Searching:  SE2q-bKlajGARvZ@domain.com
I20210818-12:42:56.622(4)? found:  SE2q-bKlajGARvZ@domain.com
I20210818-12:42:56.623(4)? Spent 3572ms for Case Insensitive Regexp
=> Meteor server restarted                    
I20210818-12:43:28.164(4)? {
I20210818-12:43:28.165(4)?   r: [
I20210818-12:43:28.165(4)?     { _id: 'wG6poKsbfhC3RiBCy', emails: [Array] },
I20210818-12:43:28.165(4)?     { _id: 'xuXgh8kEq4HDzWzaG', emails: [Array] },
I20210818-12:43:28.165(4)?     { _id: 'Ld8BWwY5Rz2gMRmx4', emails: [Array] },
I20210818-12:43:28.165(4)?     { _id: 'rHA2CgAXpLDnhsYhZ', emails: [Array] },
I20210818-12:43:28.165(4)?     { _id: 'eyvq3vvEdPgPfLcQB', emails: [Array] },
I20210818-12:43:28.165(4)?     { _id: 'Fi7iX5ii6XKGDBgCq', emails: [Array] },
I20210818-12:43:28.165(4)?     { _id: 'x8FWLzZiqQMLFvjzy', emails: [Array] },
I20210818-12:43:28.165(4)?     { _id: 'fZyzD5B6vn3sqZ7YN', emails: [Array] },
I20210818-12:43:28.165(4)?     { _id: 'xRgY2tuKzmMdafBjT', emails: [Array] },
I20210818-12:43:28.165(4)?     { _id: 'EBxWbf4Ba6S3dvPGd', emails: [Array] }
I20210818-12:43:28.165(4)?   ]
I20210818-12:43:28.165(4)? }
I20210818-12:43:28.165(4)? Searching:  FJQR-m8bnSJ9fsV@domain.com
I20210818-12:43:28.170(4)? found:  FJQR-m8bnSJ9fsV@domain.com
I20210818-12:43:28.170(4)? Spent 6ms for Selector For Fast Case Insensitive Lookup
I20210818-12:43:28.170(4)? Searching:  4UKg-xQQTNQ4f7G@domain.com
I20210818-12:43:28.173(4)? found:  4UKg-xQQTNQ4f7G@domain.com
I20210818-12:43:28.174(4)? Spent 3ms for Selector For Fast Case Insensitive Lookup
I20210818-12:43:28.174(4)? Searching:  wdIP-QqgxcSTtsY@domain.com
I20210818-12:43:28.178(4)? found:  wdIP-QqgxcSTtsY@domain.com
I20210818-12:43:28.178(4)? Spent 4ms for Selector For Fast Case Insensitive Lookup
I20210818-12:43:28.178(4)? Searching:  LwUI-oXBhBXJmNZ@domain.com
I20210818-12:43:28.183(4)? found:  LwUI-oXBhBXJmNZ@domain.com
I20210818-12:43:28.183(4)? Spent 4ms for Selector For Fast Case Insensitive Lookup
I20210818-12:43:28.183(4)? Searching:  q9b2-h1HtQ5nLrW@domain.com
I20210818-12:43:28.187(4)? found:  q9b2-h1HtQ5nLrW@domain.com
I20210818-12:43:28.187(4)? Spent 4ms for Selector For Fast Case Insensitive Lookup
I20210818-12:43:28.187(4)? Searching:  E0Nf-qQ62p90HC3@domain.com
I20210818-12:43:28.191(4)? found:  E0Nf-qQ62p90HC3@domain.com
I20210818-12:43:28.191(4)? Spent 4ms for Selector For Fast Case Insensitive Lookup
I20210818-12:43:28.191(4)? Searching:  0mbX-XxhiJRrKFN@domain.com
I20210818-12:43:28.195(4)? found:  0mbX-XxhiJRrKFN@domain.com
I20210818-12:43:28.195(4)? Spent 4ms for Selector For Fast Case Insensitive Lookup
I20210818-12:43:28.195(4)? Searching:  ilza-yEA5trzzLc@domain.com
I20210818-12:43:28.199(4)? found:  ilza-yEA5trzzLc@domain.com
I20210818-12:43:28.199(4)? Spent 4ms for Selector For Fast Case Insensitive Lookup
I20210818-12:43:28.199(4)? Searching:  44DX-ZYqRvAHTjz@domain.com
I20210818-12:43:28.202(4)? found:  44DX-ZYqRvAHTjz@domain.com
I20210818-12:43:28.203(4)? Spent 3ms for Selector For Fast Case Insensitive Lookup
I20210818-12:43:28.203(4)? Searching:  IKAf-NzRSDl95lj@domain.com
I20210818-12:43:28.207(4)? found:  IKAf-NzRSDl95lj@domain.com
I20210818-12:43:28.207(4)? Spent 4ms for Selector For Fast Case Insensitive Lookup



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants