Accounts.createUser selector has empty params

Hi, I’ve noticed something weird in MontiAPM: the createUser function seems to run _createUserCheckingDuplicates with a blank username and email every time a user creates an account on my site.

Here’s the function in question [Github]:

_createUserCheckingDuplicates({ user, email, username, options }) {
    const newUser = {
      ...user,
      ...(username ? { username } : {}),
      ...(email ? { emails: [{ address: email, verified: false }] } : {}),
    };

    // Perform a case insensitive check before insert
    this._checkForCaseInsensitiveDuplicates('username', 'Username', username);
    this._checkForCaseInsensitiveDuplicates('emails.address', 'Email', email);

    const userId = this.insertUserDoc(options, newUser);
    // Perform another check after insert, in case a matching user has been
    // inserted in the meantime
    try {
      this._checkForCaseInsensitiveDuplicates('username', 'Username', username, userId);
      this._checkForCaseInsensitiveDuplicates('emails.address', 'Email', email, userId);
    } catch (ex) {
      // Remove inserted user if the check fails
      Meteor.users.remove(userId);
      throw ex;
    }
    return userId;
  }

But when I view this in MontiAPM, it’s showing these queries often take 1+ seconds (in some cases 10+ seconds), and the selectors are blank.

The user accounts are created without issue, but this seems to slow down my setup a little bit.

Anyone else seeing something similar?

Hi @jasongrishkoff
We will be testing it internally, @denyhs will be helping us with this one

Hi @jasongrishkoff,

I’ve been taking a look, and I found what’s happening. But I can already assure you that the query is working as it should, with the correct parameters, otherwise, creating a user would not be working with those Meteor methods.

The problem is that you can’t stringify a regex expression (javascript - Serialization of RegExp - Stack Overflow). I was able to test this in a new app (the two images below). The first image shows a normal call to JSON.stringify:

console.log('_checkForCaseInsensitiveDuplicates', JSON.stringify(obj));

And the second shows the result for this call:

function stringifyFilter(key,value) { 
     if (value instanceof RegExp) { return value.toString(); } 

     return value; 
} 

console.log('_checkForCaseInsensitiveDuplicates', JSON.stringify(obj, stringifyFilter));

Also, I could reproduce the same thing you got on MontiAPM on our APM. This information is sent to APM already stringified, which means it arrives already in that format. Unfortunately, I wasn’t to find exactly who sends this information to the APM UI, and it needs more time to solve this.

We’ll look more into this later for APM, and the people responsible for MontiAPM will also have to look on their side (they use a fork from our APM). Cc @zodern.

But for now, don’t worry. The query is correct. And the query time will variate accordingly to the user’s collection size.

Great, thanks for letting me know!