Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: [FIX] JavaScript CPU overload in Article Editor (sNews 1.5RC1)  (Read 7458 times)

sevir

  • Newbie
  • *
  • Karma: 0
  • Posts: 21
    • http://www.sevir.org
[FIX] JavaScript CPU overload in Article Editor (sNews 1.5RC1)
« on: October 12, 2006, 10:16:39 PM »

Well, I develop with a notebook computer, normally, the cpu fan is totally stopped but I surprised when I edited with sNews my web site my cpu fan ran more and more fast, ummm, I wached in task manager and... wow!! My firefox was with 76% of CPU load, and only I loaded my sNews web site in simple editor mode... mmm that preview feature...

So I am watching the snews code, and ahhh!!! preview panel is refresed each 5 miliseconds aggg!!
in sNews 1.5
Line 1770:   if (allowpreview == true) { window.onLoad = startPreview(); }
Line 1771:   function startPreview() { window.self.setInterval("updatePreview()", 5); }

In one second the preview panel is refreshed 1000 / 5 = 200 times by second ahhh!!!!!! but but... if my monitor is 60Hz (refresh 60 times by second), how the preview panel is refreshed more times than my monitor?? :P It is impossible that I can see that :D

Well, I use a WYSIWYG editor so I don't need refresh the preview panel each time, but I want the posibility of do that when I want. My solution is refresh the panel when I click some link, by example the preview panel title.

1. I open with my text editor the file snews.php
2. I find "preview" three times in the code, I get the
line 1163:
  html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', l('preview'));
I change it for:
  html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', ''.l('preview').'');

3. I need to change the Javascript code, I find "updatePreview", I get the
line 1771:
   function startPreview() { window.self.setInterval("updatePreview()", 5); }
I change it for:
   function startPreview() {  updatePreview();    }


Ok I get a beautiful "onpush" preview ;-). Also you can the refresh number, a normal animation run in 25 photogrames by second, that is one refresh in 40 miliseconds. But anyway normally you don't see the preview panel at the same time that you edit the post, you can write a more big number, 200 or 300 miliseconds is a good number. Your CPU thank you :D
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
[FIX] JavaScript CPU overload in Article Editor (sNews 1.5RC1)
« Reply #1 on: October 13, 2006, 02:28:21 AM »

Welcome to our sNews Community sevir. Actually, this issue has been discussed in a few topics on other forums here. The first solution - http://www.solucija.com/forum/viewtopic.php?pid=13099#p13099 - was to change the 5 to 1000, resulting in a refresh rate of 1 second rather than .005 second.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
[FIX] JavaScript CPU overload in Article Editor (sNews 1.5RC1)
« Reply #2 on: October 13, 2006, 07:20:39 AM »

And the bug is solved in the next release that is a'coming...
Logged
My sNews site
"It's only dead fish that goes with the flow... "
Updated, online again - Free designs

sevir

  • Newbie
  • *
  • Karma: 0
  • Posts: 21
    • http://www.sevir.org
[FIX] JavaScript CPU overload in Article Editor (sNews 1.5RC1)
« Reply #3 on: October 13, 2006, 08:33:59 AM »

Ok, I searched for some similar topic in the forum and I don't see any similar in the results ;), sorry.

Another question, I just search for another (bug?), :D, searching "p pages" I just found the CPU overload topic :P. Ok, my problem is when I create one page, the SEF title I write some with "p", programs, programme,.... I create the page normally but when I click in the link home/programme/ I go to the home page ?? , I changed the SEF title to computering by example and all works ok. I don't see the code about this at the moment but also I don't found nothing in the forum. Do you know something about that? Thanks.
Logged

sevir

  • Newbie
  • *
  • Karma: 0
  • Posts: 21
    • http://www.sevir.org
[FIX] JavaScript CPU overload in Article Editor (sNews 1.5RC1)
« Reply #4 on: October 13, 2006, 09:02:31 AM »

Ok, I found http://www.solucija.com/forum/viewtopic.php?id=1691 Thanks for all. Anyway I prefer preview onclick better than inInterval, so I get more control.
Logged

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
[FIX] JavaScript CPU overload in Article Editor (sNews 1.5RC1)
« Reply #5 on: October 13, 2006, 09:27:46 AM »

suit yourself :)

btw, I like that cocacola site of yours ;)
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

sevir

  • Newbie
  • *
  • Karma: 0
  • Posts: 21
    • http://www.sevir.org
[FIX] JavaScript CPU overload in Article Editor (sNews 1.5RC1)
« Reply #6 on: October 16, 2006, 01:29:06 PM »

Quote from: mika
btw, I like that cocacola site of yours ;)
Thanks, I like this font :P
Logged

Armen

  • Sr. Member
  • ****
  • Karma: 41
  • Posts: 338
    • http://www.funnydays.ru
[FIX] JavaScript CPU overload in Article Editor (sNews 1.5RC1)
« Reply #7 on: November 01, 2006, 07:51:51 AM »

sevir, you saved me, man. This OnClick solution was a real revelation for me.

Great job.
Logged
Now ogres, oh, they're much worse. They'll make a suit from your freshly peeled skin. They'll shave your liver, squeeze the jelly from your eyes... Actually, it's quite good on toast.

mininovax

  • Newbie
  • *
  • Karma: 1
  • Posts: 44
    • http://www.ondapc.net
[FIX] JavaScript CPU overload in Article Editor (sNews 1.5RC1)
« Reply #8 on: November 07, 2006, 01:52:23 AM »

also, with the new 1.5 RC3, The same issue applies. Not hard to do, just put some flash or a banner with alot of javascript, and it goes wild,

basically the js used to give you the "as you type, you see it" effect is a "refresh rate setting" that is basically sucking the cpu dry

A fix, still working on it.

The simplest solution that I have managed to implement without editing alot is

Find "function startPreview() { window.self.setInterval("updatePreview()"

Change:
function startPreview() { window.self.setInterval("updatePreview()", 5); } = .005 second

For:
function startPreview() { window.self.setInterval("updatePreview()", 3000); } = 3 seconds


no need to edit anything else... i dont think. I have found an area that states changing quite a few things ... but this is the only real reason why the refresh occurs, so I dont understand why they changed other things... could be I am missing something... but it works for me.
Logged

mosh

  • Hero Member
  • *****
  • Karma: 77
  • Posts: 510
  • Awesome day :)
    • cms-zen
[FIX] JavaScript CPU overload in Article Editor (sNews 1.5RC1)
« Reply #9 on: February 24, 2007, 08:24:45 PM »

hey, i have installed 1531 and try to do the OnClick solution, it do not expend the preview window,
when i click the preview link.

i used that OnClick solution, with the latest 153 stable release, was working fine.

with the new snews 1531 it wont work, not online or offline.

thanks for any help  :)