There's Too much CPU usage with this template

Rate this topic: Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.1.00 out of 6 based on 1 vote(s)
GK User
Thu Feb 06, 2014 11:08 am
Reply with quote
Report this post
Line No. 158 in the file "templates/gk_instyle/js/gk.scripts.js" causes very cool recursion in browser. Apart from this, generates unnecessary requests to the server, which consumes a lot of server resources. I found it after receiving a letter from the hosting company stating that script consumes more than 3% of CPU resources on the server.
In "Raw access logs" of Apache in a few seconds there is a request "POST / index.php? Tmpl = json HTTP/1.1" My site is still under construction and its address knows only client. Last night requests were from 2 IP address only, mine and my client's. We were left opend the site in the browser. What would be the case if not only 2 but 100 visitors generated queries in 5 seconds all night?
For me I solved the problem, so far as deleted lines 157, 158 and 159.

Code: Select all
setTimeout(function() {
   gkCartDataRequest();
}, 5000);


The functionality of the shopping cart not changed.
User avatar
Fresh Boarder

GK User
Thu Feb 06, 2014 3:32 pm
Reply with quote
Report this post
Hello,

The mentioned code is responsible for getting amount of products in the cart. Of course if you will remove it - then it won't display the counter but cart will work. Unfortunately there is no other way to display the counter near the shopping cart.
User avatar
Administrator

GK User
Thu Feb 06, 2014 4:49 pm
Reply with quote
Report this post
On the contrary. It works and the counter shows correct count but is refreshed after closing the message in the pop-up window "continue shopping", "show cart". The counter refreshes also after removing product from cart. Not refreshed every 5 seconds. I think it is not necessary.
Code: Select all
if(btn) {
   var counter = new Element('i', { 'id': 'gkCartCounter'});
   counter.inject(btn);
   var gkCartDataRequest = function() {
      new Request.HTML({
         url: $GK_URL + 'index.php?tmpl=json',
         onSuccess: function(nodes, xml, text) {
            document.id('gkCartCounter').set('text', '(' + text + ')');   
         },
         onComplete: function() {
         }
      }).send();   
   }
   gkCartDataRequest();
}

Tree or four lines after cited, the function gkCartDataRequest() is called. That ensures appropriate work of the counter in the position "cart"
User avatar
Fresh Boarder

GK User
Thu Feb 06, 2014 6:11 pm
Reply with quote
Report this post
But which code refreshes a counter after closing popup or removing items from the cart? Because in the original script when you remove the timeout code the counter code will be generated only on the start. Did you made some additional modifications in the script?
User avatar
Administrator

GK User
Fri Feb 07, 2014 6:14 am
Reply with quote
Report this post
Yes. Many things I've changed but they have no connection with this case. I've tested completely fresh installation, on another domain, from "gk_instyle_quickstart_J!25" with only deleted three lines 157, 158 and 159 from the file templates/gk_instyle/js/gk.script.js
One major change is described in this thread: Virtuemart Shopping Cart Products Not Showing on Cart Page
User avatar
Fresh Boarder


cron