Skip to content
This repository has been 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
Projects

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 "John.Doe@example.com");
  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 added the QA in progress We are checking label Jul 13, 2019
@TomashKhamlai TomashKhamlai moved this from Dev In Progress to Ready for Grooming in Backlog Jul 13, 2019
@m2-community-project m2-community-project bot moved this from Ready for Grooming to Dev In Progress in Backlog Jul 13, 2019
@TomashKhamlai TomashKhamlai changed the title [Draft] Investigate the changes in createEmptyCart for Customer Investigate the changes in createEmptyCart for Customer Jul 13, 2019
@TomashKhamlai TomashKhamlai moved this from Dev In Progress to Ready for Grooming in Backlog Jul 13, 2019
@m2-community-project m2-community-project bot moved this from Ready for Grooming to Dev In Progress in Backlog Jul 13, 2019
@m2-community-project m2-community-project bot moved this from Dev In Progress to Ready for Grooming in Backlog Jul 13, 2019
@TomashKhamlai
Copy link
Contributor Author

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

@TomashKhamlai TomashKhamlai removed the QA in progress We are checking label Jul 23, 2019
@pmclain pmclain self-assigned this Jul 31, 2019
@m2-community-project m2-community-project bot moved this from Ready for Grooming to Dev In Progress in Backlog Jul 31, 2019
@m2-community-project m2-community-project bot moved this from Dev In Progress to Pull Request In Progress in Backlog Jul 31, 2019
@sidolov sidolov closed this as completed Aug 13, 2019
@m2-community-project m2-community-project bot moved this from Pull Request In Progress to Done in Backlog Aug 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Backlog
  
Done
Development

No branches or pull requests

3 participants