Kaynağa Gözat

Get tthe total amount for stats from URL and do not calculate it

poeti8 6 yıl önce
ebeveyn
işleme
14aab453fa
2 değiştirilmiş dosya ile 1 ekleme ve 4 silme
  1. 1 0
      server/controllers/urlController.js
  2. 0 4
      server/db/url.js

+ 1 - 0
server/controllers/urlController.js

@@ -297,6 +297,7 @@ exports.getStats = async ({ query: { id, domain }, user }, res) => {
   const [url] = urls;
   const stats = await getStats({ id, domain: customDomain, user });
   if (!stats) return res.status(400).json({ error: 'Could not get the short URL stats.' });
+  stats.total = url.count && url.count.toNumber ? url.count.toNumber() : 0;
   stats.shortUrl = `http${!domain ? 's' : ''}://${
     domain ? url.domain : process.env.DEFAULT_DOMAIN
   }/${url.id}`;

+ 0 - 4
server/db/url.js

@@ -314,8 +314,6 @@ exports.getStats = ({ id, domain, user }) =>
       },
     };
 
-    let total = 0;
-
     const statsPeriods = [[1, 'lastDay'], [7, 'lastWeek'], [30, 'lastMonth']];
 
     session
@@ -340,7 +338,6 @@ exports.getStats = ({ id, domain, user }) =>
       )
       .subscribe({
         onNext(record) {
-          total += 1;
           const browser = record.get('browser');
           const os = record.get('os');
           const country = record.get('country');
@@ -383,7 +380,6 @@ exports.getStats = ({ id, domain, user }) =>
           stats.lastMonth.stats = statsObjectToArray(stats.lastMonth.stats);
           stats.allTime.stats = statsObjectToArray(stats.allTime.stats);
           const response = {
-            total,
             id,
             updatedAt: new Date().toISOString(),
             lastDay: stats.lastDay,