Drupal and Slow Machines - Node Editing

My machine is a few years old now, it was very generously given to me by a mad video engineer called Andy. The machine is a Dell Dimensions 4700 with 2GB RAM and a stock setup like this:

processor       : 0
vendor_id       : GenuineIntel
cpu family      : 15
model           : 3
model name      : Intel(R) Pentium(R) 4 CPU 2.80GHz
stepping        : 4
cpu MHz         : 2793.276
cache size      : 1024 KB

I have done a lot of work with Drupal 7 lately and I started to notice that even low-budget hosting services were running sites faster than my machine so I decided what I could do to try speed up Drupal development and make my life a bit zingier. I can't afford to buy a new machine just yet but eBuyer are in my sights!

WYSIWYG Editing

One of the things that drives me nuts is having to edit HTML from a node body, on my machine it is getting irritating waiting for five to ten seconds for the page to load in the CMS just to make some changes and then the same amount of time again to save it. The irony is that all I want to do is change the node body and refresh the browser page to see how it went.

I first considered re-writing a utility I wrote years back called 'shoveit'; it was a BASH script that wrote the contents of a file directly to a node table. Of course, Drupal 7 is so utterly radically brilliant (and different) compared to Drupal 6 that I discovered 'real classes' inside the Drupal framework! Not wanting to make *today* the day I get better about knowing how Drupal 7 works I went for the simplest thing possible, which initially looked like it might ba a small PHP file that did something like:

UPDATE `tablename`.`field_data_body` SET `body_value` = 'new data here'
' WHERE `field_data_body`.`entity_type` = 'node' AND `field_data_body`.`deleted` = 0 
AND `field_data_body`.`entity_id` = 4 
AND `field_data_body`.`language` = 'und'
AND `field_data_body`.`delta` = 0;

truncate cache_field;

The nid and vid would have been command line parameters as would the file-name, then a quick file_get_contents followed by a call to mysql_escape_string() and basically job done.

The more I looked into it the more I didn't like it for many reasons. In the end the answer was obvious and I now use this system until I have got the page just how I like it, then I can paste the file back into the node vody for the final time!

The Solution

First of all create a folder under the 'sites' folder, I call mine 'static' sites/default/files/static. Then I create an HTML file containing the stuff that I want in the page, or a PHP file if appropriate. Whatever you need to make your editor syntax highlight for you! Once you have that file, copy the contents of the node you are fed up with editing in the CMS into this file and save it, in my case it was about.us.html as it was plain HTML.

Finally, in the node that you are editing, change the type to PHP Code and then add this as the one and only line:

echo file_get_contents(getcwd() . "/sites/default/files/about.us.html");

Save the node and that's it. All you do now is edit the static file and refresh the page like you are used to. It has made quite a difference to me anyway, until I can get the mother-of-all uber-fast OS free boxes from eBuyer. Once you have got the page looking like you want then do a final cut and paste back into the node body and that's it. Job done with minimum fuss and waiting for slow machines.

The main reason I steered away from writing to the DBMS: breakage! LOL... it's always a last resort with any system and particularly Drupal where the entities are wrapped in code and have a lot of behaviour that wouldn't be trigged i.e. all the node load / save / update logic would be completely by-passed by such a script, always a recipe for disaster.

Enjoy! :)

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <pre> <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or class="OPTIONS" [title="the title"].
  • Lines and paragraphs break automatically.

Full HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or class="OPTIONS" [title="the title"].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.