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

Investigate the changes in createEmptyCart for Customer #773

Closed
TomashKhamlai opened this issue Jul 13, 2019 · 2 comments
Closed

Investigate the changes in createEmptyCart for Customer #773

TomashKhamlai opened this issue Jul 13, 2019 · 2 comments
Assignees

Comments

@TomashKhamlai
Copy link
Contributor

TomashKhamlai commented Jul 13, 2019

Preconditions (*)

  1. Customer is registered
  2. Product in stock

Steps to reproduce (*)

  1. Generate Customer token
  2. Create an empty Cart and add product (or add a product to Cart)
  3. Use createEmptyCart > 499 times using this script:
#!/bin/bash
### The next line should look this graphql='http://gql-ce.io/graphql';
graphql='http://REPLACE/graphql';

# Create Token
function generateCustomerToken () {
  local email=$(echo "[email protected]");
  local password="123123qA";

  if [[ -z "$2" ]]; then
    local email_a=${email};
    local password_a=${password};
  else
    local email_a="$1";
    local password_a="$2";
  fi

    read -r -d '' query << 'QUERY'
mutation generateCustomerToken(
    $email: String!
    $password: String!
) {
    generateCustomerToken(
        email: $email
        password: $password
    ) {
        token
    }
}
QUERY
    read -r -d '' variables << VARIABLES
{
    "email": "${email_a}",
    "password": "${password_a}"
}
VARIABLES
    query='{"query":"'${query//[[:space:]]/ }'"'${variables:+',"variables":'}${variables:+${variables//[[:space:]]/ }}};
    query=${query//+([[:blank:]])/ };
    local response=$(curl \
        -X POST ${graphql} \
        -H 'Content-Type: application/json' \
        -d "$query"
    );
    customer_token=$(echo ${response} | jq -r '.data.generateCustomerToken.token');
}

function createEmptyCartForCustomer () {
read -r -d '' query << 'QUERY'
    mutation {
      createEmptyCart
    }
QUERY
    query='{"query":"'${query//[[:space:]]/ }'"'}
    query=${query//+([[:blank:]])/ }

    local response=$(curl \
        -X POST ${graphql} \
        -H 'Content-Type: application/json' \
        -H "Authorization: Bearer $customer_token" \
        -d "$query"
    ) && cart_id=$(echo ${response} | jq -r '.data.createEmptyCart');
}

generateCustomerToken
# 500 is a pager limit in phpstorm
for (( i = 1; i < 505; i++ )); do
	createEmptyCartForCustomer; 
done

echo "$cart_id";
  1. Prepare cart for placing order
  2. Place order
  3. Perform query to MySQL to count the number of occurrences, If your MySQL is not on Docker then it can be simplified
mysql -uroot -p123123q -h127.0.0.1 -e'SELECT quote_id, count(*) as NUMBER FROM gqlce.quote_id_mask GROUP BY quote_id';

My result is

+----------+--------+
| quote_id | NUMBER |
+----------+--------+
|        1 |      1 |
|        2 |      1 |
|        3 |   2770 |
+----------+--------+

But your's should look like:

+----------+--------+
| quote_id | NUMBER |
+----------+--------+
|        1 |    505 |
+----------+--------+

Expected result (*)

  1. Old behavior, the same quote_masked_id on every request for createEmptyCart if valid Customer token was used. Why waste memory? We have only 2,147,483,647 records available.

Actual result (*)

  1. Hige amount of records referencing the same quote.
  2. Haven't found the ticket about these changes.
@TomashKhamlai
Copy link
Contributor Author

@naydav, please verify this issue

@TomashKhamlai TomashKhamlai changed the title [Draft] Investigate the changes in createEmptyCart for Customer Investigate the changes in createEmptyCart for Customer Jul 13, 2019
@TomashKhamlai
Copy link
Contributor Author

Proper behavior should be protected by (integration/api-functional) tests.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants