public inbox for [email protected]  
help / color / mirror / Atom feed
From: Aditya Toshniwal <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin4][RM3475] Execution time for a query or function shows only minutes part and not hour part
Date: Tue, 15 Jan 2019 19:17:44 +0530
Message-ID: <CAM9w-_mb+SQwLbxRnUALXBHZ9QVr=t49tXgoXFL865nqdehFBQ@mail.gmail.com> (raw)

Hi Hackers,

Attached is the patch to also display the hour part if the query execution
exceeds more than 1 hour, with some improvements is code. Test case added.

Kindly review.

-- 
Thanks and Regards,
Aditya Toshniwal
Software Engineer | EnterpriseDB Software Solutions | Pune
"Don't Complain about Heat, Plant a tree"


Attachments:

  [application/octet-stream] RM3475.patch (2.5K, 3-RM3475.patch)
  download | inline diff:
diff --git a/web/pgadmin/static/js/sqleditor/calculate_query_run_time.js b/web/pgadmin/static/js/sqleditor/calculate_query_run_time.js
index b163aac5..ba390511 100644
--- a/web/pgadmin/static/js/sqleditor/calculate_query_run_time.js
+++ b/web/pgadmin/static/js/sqleditor/calculate_query_run_time.js
@@ -10,24 +10,25 @@
 import moment from 'moment';
 
 export function calculateQueryRunTime(startTime, endTime) {
-  const tempEndDate = moment(endTime);
-  let miliseconds = tempEndDate.diff(startTime);
-  let seconds = tempEndDate.diff(startTime, 'seconds');
-  const minutes = tempEndDate.diff(startTime, 'minutes');
-
+  let total_ms = moment(endTime).diff(startTime);
   let result = '';
-  if (minutes > 0) {
-    result += minutes + ' min ';
-    seconds -= minutes * 60;
-  }
+  let secs, mins, hrs;
+
+  /* Extract seconds from millisecs */
+  secs = parseInt(total_ms/1000);
+  total_ms = total_ms%1000;
+
+  /* Extract mins from seconds */
+  mins = parseInt(secs/60);
+  secs = secs%60;
 
-  if (seconds > 0) {
-    result += seconds + ' secs ';
-    miliseconds -= seconds * 1000;
-  }
+  /* Extract hrs from mins */
+  hrs = parseInt(mins/60);
+  mins = mins%60;
 
-  if(minutes <= 0) {
-    result += miliseconds + ' msec';
-  }
+  result = (hrs>0 ? hrs + ' hr ': '')
+          + (mins>0 ? mins + ' min ': '')
+          + (hrs<=0 && secs>0 ? secs + ' secs ': '')
+          + (hrs<=0 && mins<=0 ? total_ms + ' msec ':'');
   return result.trim();
 }
diff --git a/web/regression/javascript/sqleditor/calculate_query_run_time_spec.js b/web/regression/javascript/sqleditor/calculate_query_run_time_spec.js
index e5a58fe9..5d41813f 100644
--- a/web/regression/javascript/sqleditor/calculate_query_run_time_spec.js
+++ b/web/regression/javascript/sqleditor/calculate_query_run_time_spec.js
@@ -79,4 +79,27 @@ describe('#calculateQueryRunTime', () => {
           .toEqual('9 min 54 secs');
     });
   });
+
+  describe('time difference is bigger then 1 hour', () => {
+    it('displays seconds, milliseconds', () => {
+      let startDate = moment({
+        years:2018,
+        months:4,
+        date:2,
+        hours:10,
+        minutes:30,
+        seconds:20,
+        milliseconds:123}).toDate();
+      let endDate = moment({
+        years:2018,
+        months:4,
+        date:2,
+        hours:11,
+        minutes:40,
+        seconds:15,
+        milliseconds:70}).toDate();
+      expect(calculateQueryRunTime(startDate, endDate))
+          .toEqual('1 hr 9 min');
+    });
+  });
 });


view thread (2+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [pgAdmin4][RM3475] Execution time for a query or function shows only minutes part and not hour part
  In-Reply-To: <CAM9w-_mb+SQwLbxRnUALXBHZ9QVr=t49tXgoXFL865nqdehFBQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox