Possible update counterCache Function

I haven’t tested this yet. But it is a possible update counterCache function.

 

<code>

function counterCheck( )

{

 

$counterTemplate =

“UPDATE :atable AS :amodel

SET :counter = (

SELECT COUNT(:model.id)

FROM :table AS :model

WHERE :model.:foreignkey = :amodel.id

)”;

 

$updates = array();

 

$models = Configure::listObjects(‘model’) ;

 

foreach ($models as $model) {

$this->loadModel($model);

$mainTable = Inflector::tableize($model);

if (!empty($this->$model->belongsTo)) {

foreach ($this->$model->belongsTo as $assocModel =>

$def) {

if (isset($def[‘counterCache’]) &&

$def[‘counterCache’]) {

$assocTable =

Inflector::tableize($def[‘className’]);

$assocClass = $def[‘className’];

$foreignKey = $def[‘foreignKey’];

$counter = strtolower($model) . ‘_count’;

$query = String::insert($counterTemplate,

array(

‘table’ => $mainTable,

‘model’ => $model,

‘atable’ => $assocTable,

‘amodel’ => $assocModel,

‘foreignkey’ => $foreignKey,

‘counter’ => $counter

));

$result = $this->Configuration->query($query);

$affectedRows = $this->Configuration-

>getAffectedRows();

$updates[] = array(

‘query’ => $query,

‘affected_rows’ => $affectedRows

);

}

}

}

}

 

$this->set(‘updates’, $updates);

 

}

 

</code>

monitor the memory usage of unix server

“To monitor the memory usage of unix server, you can log in and run the ‘top’ command at the command line.  Hit q to quit the program

 On the Swap line, if the free value approaches zero, the system is seriously running out of RAM.  Another symptom is the load average (on the top line) hits 5 or more.  The load average is the number of processes ready and waiting to run over short/medium/long time spans.

If you see the load average creeping up and there is no real reason, run ‘service httpd restart’ and then we will have to tweak the settings some more.”

— master p

service httpd restart

If you notice the server starting to thrash, as root you can type “service httpd restart” and Apache will be restarted freeing all the memory it has consumed.  However, but the time it has reached this point, it is hard to log in and run any commands.

FlowingData: How to Make an Interactive Network Visualization

I have looked at d3 network visualization demos / tutorials before. I always tell myself I will do it. But I need to get on this. Link below is to a tutorial on flowing data. https://www.google.com/producer/editions/CAowtpoM/flowingdata/CAIiEP1jg1drOnN8PC3TcT9b0fUqMggEIhDlFy4k5ajnTsfC5QXSbl75KhwIACIQ_IySbXiwavHpyb8VqOTmZCoGCAowtpoM/how_to_make_an_interactive_netwo