Track publish time #329

Merged
bones7242 merged 4 commits from track-publish-time into master 2018-01-23 06:50:18 +01:00
2 changed files with 8 additions and 6 deletions
Showing only changes of commit a468485d33 - Show all commits

View file

@ -63,14 +63,14 @@ module.exports = {
sendGoogleAnalyticsTiming (action, headers, ip, originalUrl, startTime, endTime) {
const visitorId = ip.replace(/\./g, '-');
const visitor = ua(googleApiKey, visitorId, { strictCidFormat: false, https: true });
const time = endTime - startTime;
const publishDurration = endTime - startTime;
let params;
switch (action) {
case 'PUBLISH':
params = {
userTimingCategory : 'lbrynet',
userTimingVariableName: 'publish',
userTimingTime : time,
userTimingTime : publishDurration,
uip : ip,
ua : headers['user-agent'],
ul : headers['accept-language'],
@ -82,6 +82,7 @@ module.exports = {
if (err) {
logger.error('Google Analytics Event Error >>', err);
}
logger.info(`publish completed successfully in ${publishDurration}ms`);
});
},
};

View file

@ -128,7 +128,8 @@ module.exports = (app) => {
app.post('/api/claim-publish', multipartMiddleware, ({ body, files, headers, ip, originalUrl, user }, res) => {
logger.debug('api/claim-publish body:', body);
logger.debug('api/claim-publish files:', files);
const startTime = Date.now();
const publishStartTime = Date.now();
logger.debug('publish request started @', publishStartTime);
let name, fileName, filePath, fileType, nsfw, license, title, description, thumbnail, channelName, channelPassword;
// validate the body and files of the request
try {
@ -170,9 +171,9 @@ module.exports = (app) => {
lbryTx: result,
},
});
const endTime = Date.now();
console.log('publish end time', endTime);
sendGoogleAnalyticsTiming('PUBLISH', headers, ip, originalUrl, startTime, endTime);
const publishEndTime = Date.now();
logger.debug('publish request completed @', publishEndTime);
sendGoogleAnalyticsTiming('PUBLISH', headers, ip, originalUrl, publishStartTime, publishEndTime);
})
.catch(error => {
errorHandlers.handleApiError(originalUrl, ip, error, res);