Skip to content

Commit

Permalink
lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
ntraut committed Oct 8, 2020
1 parent 7f25d47 commit b3f0e31
Show file tree
Hide file tree
Showing 54 changed files with 669 additions and 673 deletions.
1 change: 0 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,3 @@ build_image:
only:
- tags
cache: {}

16 changes: 10 additions & 6 deletions bin/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ const listCollection = JSON.parse(process.argv[2]);
Will dump and restore each collection from connect to connect-sandbox
*/
listCollection.forEach(async (collection) => {
if (collection !== '_Session' && collection !== '_User') {
const resultDump = await exec(`mongodump -d connect -c ${collection} --username ${MONGO_USERNAME} --password ${MONGO_PASSWORD}`);
console.log(`${collection}/resultDump:`, resultDump);
const resutlRestore = await exec(`mongorestore -d connect-sandbox -c ${collection} dump/connect/${collection}.bson --username ${MONGO_USERNAME} --password ${MONGO_PASSWORD}`);
console.log(`${collection}/resutlRestore:`, resutlRestore);
}
if (collection !== '_Session' && collection !== '_User') {
const resultDump = await exec(
`mongodump -d connect -c ${collection} --username ${MONGO_USERNAME} --password ${MONGO_PASSWORD}`,
);
console.log(`${collection}/resultDump:`, resultDump);
const resutlRestore = await exec(
`mongorestore -d connect-sandbox -c ${collection} dump/connect/${collection}.bson --username ${MONGO_USERNAME} --password ${MONGO_PASSWORD}`,
);
console.log(`${collection}/resutlRestore:`, resutlRestore);
}
});
12 changes: 6 additions & 6 deletions bin/migration_mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ conn = new Mongo(MONGO_HOST);

dbSandbox = conn.getDB('connect-sandbox');
dbSandbox.auth(MONGO_USERNAME, MONGO_PASSWORD);
dbSandbox.getCollectionNames().forEach(collection => {
if (collection !== '_Session' && collection !== '_User') {
dbSandbox.getCollection(collection).drop();
}
dbSandbox.getCollectionNames().forEach((collection) => {
if (collection !== '_Session' && collection !== '_User') {
dbSandbox.getCollection(collection).drop();
}
});
print("\nDelete previous collections")

print('\nDelete previous collections');

dbSandbox.logout();
124 changes: 60 additions & 64 deletions bin/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,137 +10,133 @@ const fs = require('fs');
const json2csv = require('json2csv');

// To be changed with the Application to Monitor
const APP_NAME = "7n3k8m-Test";
const APP_TOKEN = "f81eda23-3bab-466e-89bb-627a96ba3991";
const APP_NAME = '7n3k8m-Test';
const APP_TOKEN = 'f81eda23-3bab-466e-89bb-627a96ba3991';

function getHeaderWithToken(sessionToken) {
return {
'x-parse-application-id': 'connect',
'x-parse-session-token': sessionToken,
'content-type': 'application/json'
'content-type': 'application/json',
};
}

function writeToCSV(task, quantity, time) {
const newLine = "\r\n";
const newLine = '\r\n';
const fields = ['date', 'task', 'quantity', 'time'];
const data = {
date: new Date(),
task,
quantity,
time
};
date: new Date(),
task,
quantity,
time,
};

fs.stat('perf.csv', (err) => {
if (err === null) {
// write the actual data and end with newline
const csv = json2csv.parse(data, {header: false}) + newLine;

fs.appendFile('perf.csv', csv, (errW) => {
if (errW) throw errW;
});
}
else {
// write the headers and newline
console.log('New file, just writing headers');
const csv = json2csv.parse({}, {fields}) + newLine;
// write the actual data and end with newline
const csv = json2csv.parse(data, { header: false }) + newLine;

fs.appendFile('perf.csv', csv, (errW) => {
if (errW) throw errW;
writeToCSV(task, quantity, time);
fs.appendFile('perf.csv', csv, (errW) => {
if (errW) throw errW;
});
} else {
// write the headers and newline
console.log('New file, just writing headers');
const csv = json2csv.parse({}, { fields }) + newLine;

fs.appendFile('perf.csv', csv, (errW) => {
if (errW) throw errW;
writeToCSV(task, quantity, time);
});
}
});

});
}

async function createObjects(numberOfObject, sessionToken) {
const t0 = performance.now();
// eslint-disable-next-line no-unused-vars
for (const _ of Array(numberOfObject).keys()) {
// eslint-disable-next-line no-await-in-loop
await axios.post('http://127.0.0.1:1337/parse/classes/GameScore',
await axios.post(
'http://127.0.0.1:1337/parse/classes/GameScore',
{
score:1337,
playerName:"sample",
cheatMode:false
}
,{
headers: getHeaderWithToken(sessionToken)
});
score: 1337,
playerName: 'sample',
cheatMode: false,
},
{
headers: getHeaderWithToken(sessionToken),
},
);
}
const t1 = performance.now();
console.log(`Creation of ${numberOfObject} objects took ${ t1 - t0 } milliseconds.`);
writeToCSV('POST /classes', numberOfObject, t1 - t0)
console.log(
`Creation of ${numberOfObject} objects took ${t1 - t0} milliseconds.`,
);
writeToCSV('POST /classes', numberOfObject, t1 - t0);
}

async function readObjects(numberOfObject, sessionToken) {
const t0 = performance.now();
// eslint-disable-next-line no-unused-vars
for (const _ of Array(numberOfObject).keys()) {
// eslint-disable-next-line no-await-in-loop
await axios.get('http://127.0.0.1:1337/parse/classes/GameScore',
{
headers: getHeaderWithToken(sessionToken)
await axios.get('http://127.0.0.1:1337/parse/classes/GameScore', {
headers: getHeaderWithToken(sessionToken),
});
}
const t1 = performance.now();
console.log(`Reading of ${numberOfObject} bacthes took ${ t1 - t0 } milliseconds.`);
writeToCSV('GET /classes', numberOfObject, t1 - t0)

console.log(
`Reading of ${numberOfObject} bacthes took ${t1 - t0} milliseconds.`,
);
writeToCSV('GET /classes', numberOfObject, t1 - t0);
}

async function readObjectsWithCondition(numberOfObject, sessionToken) {
const t0 = performance.now();
// eslint-disable-next-line no-unused-vars
for (const i of Array(numberOfObject).keys()) {
// eslint-disable-next-line no-await-in-loop
await axios.get('http://127.0.0.1:1337/parse/classes/GameScore',
{
params: {
where: {"playerName":"sample","cheatMode":false},
skip: i * 100
},
headers: getHeaderWithToken(sessionToken)
}
);
await axios.get('http://127.0.0.1:1337/parse/classes/GameScore', {
params: {
where: { playerName: 'sample', cheatMode: false },
skip: i * 100,
},
headers: getHeaderWithToken(sessionToken),
});
}
const t1 = performance.now();
console.log(`Reading of ${numberOfObject} bacthes with condition took ${ t1 - t0 } milliseconds.`);
writeToCSV('GET /classes w/ condition', numberOfObject, t1 - t0)

console.log(
`Reading of ${numberOfObject} bacthes with condition took ${
t1 - t0
} milliseconds.`,
);
writeToCSV('GET /classes w/ condition', numberOfObject, t1 - t0);
}



async function checkAdd() {
try {
const response = await axios.get('http://127.0.0.1:1337/parse/login', {
params: {
password: APP_TOKEN,
username: APP_NAME
username: APP_NAME,
},
headers: {
'x-parse-application-id': 'connect',
'x-parse-revocable-session': '1'
}

});
'x-parse-revocable-session': '1',
},
});

const { sessionToken } = response.data;

await createObjects(100, sessionToken);
await readObjects(100, sessionToken);
await readObjectsWithCondition(100, sessionToken);


} catch (error) {
return console.error(error);
}

return 0;
}


checkAdd();

13 changes: 3 additions & 10 deletions docs/Insomnia-collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,7 @@
"SESSION_TOKEN": "{% response 'body', 'req_b762de04bc504fff8624f92cdb8b32f0', 'b64::JC5zZXNzaW9uVG9rZW4=::46b', 'always' %}"
},
"dataPropertyOrder": {
"&": [
"CONNECT_URI",
"SESSION_TOKEN",
"JWT_TOKEN"
]
"&": ["CONNECT_URI", "SESSION_TOKEN", "JWT_TOKEN"]
},
"isPrivate": false,
"metaSortKey": 1563204550618,
Expand All @@ -466,10 +462,7 @@
"JWT_TOKEN": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJsb2dpbiI6ImJydW5vTWF1cmljZSIsIm5hbWUiOiJCcnVub01hdXJpY2UiLCJpZCI6MjgzODk5OCwiaWF0IjoxNTYyMjI3NzM1OTQwLCJleHAiOjE1NjIzMTQxMzU5NDF9.g-uxZcEFPwqqmG16tA5-Q2fhDlUIYRGXsjnaOzvz7m4"
},
"dataPropertyOrder": {
"&": [
"CONNECT_URI",
"JWT_TOKEN"
]
"&": ["CONNECT_URI", "JWT_TOKEN"]
},
"isPrivate": false,
"metaSortKey": 1563204620660,
Expand All @@ -479,4 +472,4 @@
"_type": "environment"
}
]
}
}
Loading

0 comments on commit b3f0e31

Please sign in to comment.