[fusionregistry-commitlog] SF.net SVN: fusionregistry: [43] branches/stable_3_0_x
Brought to you by:
copland007
|
From: SVN c. <fus...@li...> - 2008-02-14 09:01:43
|
Revision: 43
http://fusionregistry.svn.sourceforge.net/fusionregistry/?rev=43&view=rev
Author: copland007
Date: 2008-02-14 01:01:47 -0800 (Thu, 14 Feb 2008)
Log Message:
-----------
Lots of cache updates, work in progress. Lots of sql query count drops on every registry page.
Implemented client side cache support for get_cf_defs and get_cf_highlight in custom_fields.php and item.php.
ad_custom_fields and ad_makes_models change to '_live' function calls to ensure live data, not cached in ACP.
Added rating_id to rating_defs cache. Added registry_stats cache item and implemented on main menu screen. Main menu statistics no longer live, they are cached, and recalculated when the registrysessions.php task item is run. Task updated to rebuild main menu stats.
Added update_stats_cache routine. Prevent duplicate sql query in show_featureditem. Changed some leftover references from 'cars' to 'items'.
Updated INSTALL.txt registrysessions.php task config information.
Modified Paths:
--------------
branches/stable_3_0_x/INSTALL.txt
branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_custom_fields.php
branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_makes_models.php
branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_rating_fields.php
branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_tools.php
branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/item.php
branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/content.php
branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/custom_fields.php
branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/functions.php
branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/ratings.php
branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/main.php
branches/stable_3_0_x/upload/sources/tasks/registrysessions.php
Modified: branches/stable_3_0_x/INSTALL.txt
===================================================================
--- branches/stable_3_0_x/INSTALL.txt 2008-02-13 19:06:25 UTC (rev 42)
+++ branches/stable_3_0_x/INSTALL.txt 2008-02-14 09:01:47 UTC (rev 43)
@@ -131,18 +131,18 @@
============================================================================
-Step 5: Configuring session cleanup task
+Step 5: Configuring periodic tasks
============================================================================
Although this step is not required it is highly recommended to keep your
ibf_registry_sessions table nice and tidy. Head into your Task Manager and
click 'Add New Task' near the bottom. Enter the following values:
-- Task Title: "Fusion Registry Session Cleanup"
-- Task Short Description: "Remove old Fusion Registry sessions"
+- Task Title: "Fusion Registry Periodic Tasks"
+- Task Short Description: "Remove old Fusion Registry sessions, recalculate main menu stats"
- Task PHP File To Run: "registrysessions.php"
- Time Options...
- - Task Time: Minutes: "0"
+ - Task Time: Minutes: "59"
- Task Time: Hours: "Every Hour"
- Task Time: Week Day: "Every Week Day"
- Task Time: Month Day: "Every Day of the Month"
Modified: branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_custom_fields.php
===================================================================
--- branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_custom_fields.php 2008-02-13 19:06:25 UTC (rev 42)
+++ branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_custom_fields.php 2008-02-14 09:01:47 UTC (rev 43)
@@ -249,9 +249,9 @@
}
// Go get our Custom Field definition
- $cf_data = $this->lib['custom_fields']->get_cf_defs( array( 'WHERE' => 'field_id='.$this->ipsclass->input['f'] ) );
+ $cf_data = $this->lib['custom_fields']->get_cf_defs_live( array( 'WHERE' => 'field_id='.$this->ipsclass->input['f'] ) );
- // Since get_cf_defs() returns an array of arrays, we are removing a layer here.
+ // Since get_cf_defs_live() returns an array of arrays, we are removing a layer here.
// The key is the field_id which was passed in from the beginning ;)
$field = $cf_data[$this->ipsclass->input['f']];
@@ -642,10 +642,10 @@
function show_fields()
{
// Grab all the custom field definitions and groups first as they will be used by a few things below
- $cf_defs = $this->lib['custom_fields']->get_cf_defs( array( 'ORDER BY' => 'field_order ASC, field_name ASC' ) );
+ $cf_defs = $this->lib['custom_fields']->get_cf_defs_live( array( 'ORDER BY' => 'field_order ASC, field_name ASC' ) );
$cf_groups = $this->lib['custom_fields']->get_cf_groups();
- $this->ipsclass->html .= $this->ipsclass->skin_acp_global->information_box( "Fusion Registry Custom Fields Overview", "You can manage your garage custom fields from here.<br /><br /><span style='color:red'><b>PLEASE NOTE:</b> You must not configure the same order number for more than 1 custom field. Doing so will result in some of your custom fields from not showing up!</span>".'<br /> ' ) . "<br >";
+ $this->ipsclass->html .= $this->ipsclass->skin_acp_global->information_box( "Fusion Registry Custom Fields Overview", "You can manage your garage custom fields from here.<br /><br /><span style='color:red'><b>PLEASE NOTE:</b> You must not configure the same order number for more than 1 custom field. Doing so will result in some of your custom fields not showing up!</span>".'<br /> ' ) . "<br >";
// Get the processed list of all custom fields and groups
$cf_processed = $this->lib['custom_fields']->process_cf_defs( array( 'cf_defs' => $cf_defs, 'cf_groups' => $cf_groups, 'type' => 'acp_highlight' ) );
@@ -826,7 +826,8 @@
// Loop through each setting
while ( $row = $this->ipsclass->DB->fetch_row() )
{
- $this->ipsclass->cache['registry_field_defs'][ $row['field_id'] ] = array( 'field_name' => $row['field_name'],
+ $this->ipsclass->cache['registry_field_defs'][ $row['field_id'] ] = array( 'field_id' => $row['field_id'],
+ 'field_name' => $row['field_name'],
'field_type' => $row['field_type'],
'field_options' => $row['field_options'],
'field_default' => $row['field_default'],
Modified: branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_makes_models.php
===================================================================
--- branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_makes_models.php 2008-02-13 19:06:25 UTC (rev 42)
+++ branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_makes_models.php 2008-02-14 09:01:47 UTC (rev 43)
@@ -717,7 +717,7 @@
$make_to_delete = substr($make_to_delete, 0, -2);
// Get our custom field def for the make field
- $cf_def = $this->lib['custom_fields']->get_cf_defs( array('WHERE' => "field_options='make'") );
+ $cf_def = $this->lib['custom_fields']->get_cf_defs_live( array('WHERE' => "field_options='make'") );
// It will/should be are first and only returned value!
$make_def = array_shift($cf_def);
@@ -890,7 +890,7 @@
$model_to_delete = substr($model_to_delete, 0, -2);
// Get our custom field def for the model field
- $cf_def = $this->lib['custom_fields']->get_cf_defs( array('WHERE' => "field_options='model'") );
+ $cf_def = $this->lib['custom_fields']->get_cf_defs_live( array('WHERE' => "field_options='model'") );
// It will/should be are first and only returned value!
$model_def = array_shift($cf_def);
Modified: branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_rating_fields.php
===================================================================
--- branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_rating_fields.php 2008-02-13 19:06:25 UTC (rev 42)
+++ branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_rating_fields.php 2008-02-14 09:01:47 UTC (rev 43)
@@ -440,7 +440,8 @@
// Loop through each setting
while ( $row = $this->ipsclass->DB->fetch_row() )
{
- $this->ipsclass->cache['registry_rating_defs'][ $row['rating_id'] ] = array( 'rating_name' => $row['rating_name'],
+ $this->ipsclass->cache['registry_rating_defs'][ $row['rating_id'] ] = array( 'rating_id' => $row['rating_id'],
+ 'rating_name' => $row['rating_name'],
'rating_order' => $row['rating_order'],
);
}
Modified: branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_tools.php
===================================================================
--- branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_tools.php 2008-02-13 19:06:25 UTC (rev 42)
+++ branches/stable_3_0_x/upload/sources/components_acp/fusionscripts/fusionregistry/ad_tools.php 2008-02-14 09:01:47 UTC (rev 43)
@@ -102,6 +102,7 @@
'registry_field_defs' => 'Custom field definitions',
'registry_rating_defs' => 'Custom rating definitions',
'registry_categories' => 'Modification categories',
+ 'registry_stats' => 'Main menu statistics',
);
switch($this->ipsclass->input['code'])
@@ -490,6 +491,15 @@
$this->ipsclass->main_msg = 'Registry modification category cache updated';
break;
+ case 'registry_stats':
+ require_once( REGISTRY_PATH.'/lib/functions.php' );
+ $this->fr_cache = new registry_functions();
+ $this->fr_cache->ipsclass =& $this->ipsclass;
+
+ $this->fr_cache->update_stats_cache();
+ $this->ipsclass->main_msg = 'Registry main menu statistics cache updated';
+ break;
+
default:
$this->ipsclass->main_msg = 'No valid cache was specified to update';
break;
Modified: branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/item.php
===================================================================
--- branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/item.php 2008-02-13 19:06:25 UTC (rev 42)
+++ branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/item.php 2008-02-14 09:01:47 UTC (rev 43)
@@ -451,11 +451,11 @@
$this->ipsclass->Error( array( LEVEL => 1, MSG => 'no_permission') );
}
- // Make sure they haven't exceeded the max vehicle limit
- $this->ipsclass->DB->query("SELECT count(*) AS total_cars FROM ibf_registry_items WHERE member_id = '". $this->ipsclass->member['id'] ."'");
+ // Make sure they haven't exceeded the max item limit
+ $this->ipsclass->DB->query("SELECT count(*) AS total_items FROM ibf_registry_items WHERE member_id = '". $this->ipsclass->member['id'] ."'");
$row = $this->ipsclass->DB->fetch_row();
- if ($row['total_cars'] >= $this->registry_config['max_user_cars'])
+ if ($row['total_items'] >= $this->registry_config['max_user_cars'])
{
// Sorry, too many vehicles :)
$data = array( message => $this->ipsclass->lang['exceeded_car_limit'],
@@ -972,11 +972,11 @@
$this->ipsclass->Error( array( LEVEL => 1, MSG => 'no_permission') );
}
- // Make sure they haven't exceeded the max vehicle limit
- $this->ipsclass->DB->query("SELECT count(*) AS total_cars FROM ibf_registry_items WHERE member_id = '". $this->ipsclass->member['id'] ."'");
+ // Make sure they haven't exceeded the max item limit
+ $this->ipsclass->DB->query("SELECT count(*) AS total_items FROM ibf_registry_items WHERE member_id = '". $this->ipsclass->member['id'] ."'");
$row = $this->ipsclass->DB->fetch_row();
- if ($row['total_cars'] >= $this->registry_config['max_user_cars'])
+ if ($row['total_items'] >= $this->registry_config['max_user_cars'])
{
// Sorry, too many vehicles :)
$data = array( message => $this->ipsclass->lang['exceeded_car_limit'],
Modified: branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/content.php
===================================================================
--- branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/content.php 2008-02-13 19:06:25 UTC (rev 42)
+++ branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/content.php 2008-02-14 09:01:47 UTC (rev 43)
@@ -30,6 +30,7 @@
/**
* Functions for the main menu HTML of the Fusion Registry
*
+ * @todo Cache all statistics
* @package Fusion Registry
* @subpackage lib
* @version $Id$
@@ -97,6 +98,8 @@
*/
function show_featureditem($in_ipdl='0')
{
+ $exists = 0;
+
// If we are using random, go fetch!
if ( $this->class->registry_config['featured_item_random'] == 1 )
{
@@ -110,12 +113,20 @@
$vehicle_data = $this->ipsclass->DB->fetch_row();
$this->class->registry_config['featured_item_id'] = $vehicle_data['id'];
+
+ $exists = 1;
}
+ else
+ {
+ // Make sure the configured item id exists
+ $this->ipsclass->DB->query("SELECT id FROM ibf_registry_items WHERE id='". $this->class->registry_config['featured_item_id'] ."'");
+ if ( $this->ipsclass->DB->get_num_rows() > 0 )
+ {
+ $exists = 1;
+ }
+ }
- // Make sure the vehicle exists
- $this->ipsclass->DB->query("SELECT id FROM ibf_registry_items WHERE id='". $this->class->registry_config['featured_item_id'] ."'");
-
- if ( $this->ipsclass->DB->get_num_rows() > 0 )
+ if ( $exists )
{
// Get our fields that are going to be displayed
$cf_highlight = $this->class->lib['custom_fields']->get_cf_highlight();
Modified: branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/custom_fields.php
===================================================================
--- branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/custom_fields.php 2008-02-13 19:06:25 UTC (rev 42)
+++ branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/custom_fields.php 2008-02-14 09:01:47 UTC (rev 43)
@@ -82,6 +82,12 @@
{
$this->class = &$class;
+ // Load the cache if needed, don't load if we're in the ACP
+ if ( !is_array( $this->ipsclass->cache['registry_field_defs'] ) && IPB_THIS_SCRIPT != 'admin' )
+ {
+ $this->ipsclass->init_load_cache( array( 'registry_field_defs' ) );
+ }
+
// Initialize post_parser if it hasn't already
if ( !is_object( $this->class->lib['parser']) )
{
@@ -131,15 +137,62 @@
/**
- * Get Custom Field definitions
+ * Get Custom Field definitions from cache
*
+ * This function's job is only to retrieve the data from the cache,
+ * it should not process the returned data.
+ *
+ * @todo Finish the ORDER BY clause for cache retrieval
+ * @param array $opts Optional custom cmd/value pair attributes
+ * @return array An array of an array, outer key is field_id
+ */
+ function get_cf_defs($opts=array(), $live=0)
+ {
+ $results = $this->ipsclass->cache['registry_field_defs'];
+
+ // Did we get any restrictions passed?
+ if ( count($opts) > 0 && is_array($this->ipsclass->cache['registry_field_defs']) )
+ {
+ // First handle the WHERE clause
+ if ( isset($opts['WHERE']) && is_array($opts['WHERE']) )
+ {
+ foreach ( $opts['WHERE'] as $where_field => $where_value )
+ {
+ foreach ( $results as $field_id => $field_row )
+ {
+ if ( $field_row[ $where_field ] != $where_value )
+ {
+ // WHERE did not match, remove from results
+ unset( $results[ $field_id ] );
+ }
+ }
+ }
+ }
+
+ // Now handle the ORDER BY clause
+ if ( isset($opts['ORDER BY']) && is_array($opts['ORDER BY']) )
+ {
+ foreach ( $opts['ORDER BY'] as $order_field => $order_value )
+ {
+ // TODO - loop through $results and re-sort
+ }
+ }
+ }
+
+ return $results;
+ }
+
+
+ /**
+ * Get Custom Field definitions from live DB (only ACP calls)
+ *
* This function's job is only to retrieve the data from the database,
* it should not process the returned data.
*
* @param array $opts Optional custom SQL cmd/value pair attributes
* @return array An array of an array, outer key is field_id
*/
- function get_cf_defs($opts=array())
+ function get_cf_defs_live($opts=array(), $live=0)
{
$query = "SELECT field_id, field_name, field_type, field_options,
field_default, field_required, field_size, field_rows,
@@ -169,13 +222,13 @@
return $cf_defs;
}
-
/**
* Get Custom Field entries
*
* This function's job is only to retrieve the data from the database,
* it should not process the returned data.
*
+ * @todo Smartly cache these calls
* @param array $opts Optional custom SQL cmd/value pair attributes
* @return array An array of an array, outer key is field_id
*/
@@ -264,45 +317,43 @@
*/
function get_cf_highlight()
{
- // Check for cached value
+ // Have we already figured this out?
if ( !empty($this->_cf_highlight) )
{
return $this->_cf_highlight;
}
else
{
- $query = 'SELECT field_id, field_name, field_type, field_options, '.
- 'field_default, field_required, field_size, field_rows, '.
- 'field_cols, field_order, field_browse, field_highlight, '.
- 'field_group_id, field_search '.
- 'FROM ibf_registry_field_defs '.
- "WHERE field_highlight = '1' ".
- 'ORDER BY field_order ASC, field_name ASC';
+ $this->_cf_highlight = array();
- $rs = $this->ipsclass->DB->query($query);
-
- // If we didn't get any, let's default to the first by order num
- if ( $this->ipsclass->DB->get_num_rows() < 1 )
+ if ( is_array($this->ipsclass->cache['registry_field_defs']) )
{
- $query = 'SELECT field_id, field_name, field_type, field_options, '.
- 'field_default, field_required, field_size, field_rows, '.
- 'field_cols, field_order, field_browse, field_highlight, '.
- 'field_group_id, field_search '.
- 'FROM ibf_registry_field_defs '.
- "WHERE field_order = '1' LIMIT 1";
+ foreach ($this->ipsclass->cache['registry_field_defs'] as $field_id => $field_row)
+ {
+ if ( $field_row['field_highlight'] == 1 )
+ {
+ // Order the results by field_order, if they have the same field_order
+ // set for more than one row this will clobber the dups. There is a
+ // warning about this in the ACP for them, but at some point the code
+ // needs to take care of that possible end-user blunder automatically.
+ $this->_cf_highlight[ $field_row['field_order'] ] = $field_row;
+ }
+ }
- $rs = $this->ipsclass->DB->query($query);
+ // If we didn't get any, let's default to the first
+ if ( count($this->_cf_highlight) < 1 )
+ {
+ $field_id = end(array_slice(array_keys($this->ipsclass->cache['registry_field_defs']), 0, 1));
+ $this->_cf_highlight[$field_id] = $this->ipsclass->cache['registry_field_defs'][$field_id];
+ }
+
+ return $this->_cf_highlight;
}
-
- // Build our Custom Field highlight data structure
- $this->_cf_highlight = array();
-
- while ( $row = $this->ipsclass->DB->fetch_row($rs) )
+ else
{
- $this->_cf_highlight[$row['field_id']] = $row;
+ // There is no cache, sorry :(
+ return array();
}
-
- return $this->_cf_highlight;
}
}
@@ -394,7 +445,7 @@
$cf_data = array();
// First off the custom field definitions
- $cf_data['cf_defs'] = $this->get_cf_defs( array('ORDER BY' => 'field_order ASC') );
+ $cf_data['cf_defs'] = $this->get_cf_defs( array('ORDER BY' => array('field_order' => 'ASC') ) );
// Grab the custom field groups
$cf_data['cf_groups'] = $this->get_cf_groups();
Modified: branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/functions.php
===================================================================
--- branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/functions.php 2008-02-13 19:06:25 UTC (rev 42)
+++ branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/functions.php 2008-02-14 09:01:47 UTC (rev 43)
@@ -305,7 +305,7 @@
$list = '';
// Make sure they haven't exceeded the max item limit
- $this->ipsclass->DB->query("SELECT count(*) AS total_cars FROM ibf_registry_items WHERE member_id = '". $this->ipsclass->member['id'] ."'");
+ $this->ipsclass->DB->query("SELECT count(*) AS total_items FROM ibf_registry_items WHERE member_id = '". $this->ipsclass->member['id'] ."'");
$row = $this->ipsclass->DB->fetch_row();
if ($row['total_cars'] < $this->class->registry_config['max_user_cars'])
@@ -388,6 +388,45 @@
return TRUE;
}
+
+
+ /**
+ * Update/Rebuild main menu statistics cache
+ *
+ * This gets run by the the session task and on demand in the ACP tools.
+ *
+ * @todo Case study needed - is this worth caching?
+ */
+ function update_stats_cache()
+ {
+ // Start with an empty cache
+ $this->ipsclass->cache['registry_stats'] = array();
+
+ // Total items
+ $items = $this->ipsclass->DB->simple_exec_query( array( 'select' => 'count(*) AS total_items',
+ 'from' => 'registry_items' ) );
+
+ // Total mods
+ $mods = $this->ipsclass->DB->simple_exec_query( array( 'select' => 'count(*) AS total_mods',
+ 'from' => 'registry_mods' ) );
+
+ // Total comments
+ $comments = $this->ipsclass->DB->simple_exec_query( array( 'select' => 'count(*) AS total_comments',
+ 'from' => 'registry_guestbooks' ) );
+
+ // Total views
+ $views = $this->ipsclass->DB->simple_exec_query( array( 'select' => 'SUM(views) AS total_views',
+ 'from' => 'registry_items' ) );
+
+ $this->ipsclass->cache['registry_stats'] = array( 'total_items' => $items['total_items'],
+ 'total_mods' => $mods['total_mods'],
+ 'total_comments' => $comments['total_comments'],
+ 'total_views' => $views['total_views'],
+ );
+
+ // Save it back to the cache_store
+ $this->ipsclass->update_cache( array( 'name' => 'registry_stats', 'array' => 1, 'deletefirst' => 1, 'donow' => 0 ) );
+ }
}
?>
Modified: branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/ratings.php
===================================================================
--- branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/ratings.php 2008-02-13 19:06:25 UTC (rev 42)
+++ branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/lib/ratings.php 2008-02-14 09:01:47 UTC (rev 43)
@@ -75,6 +75,7 @@
* This function's job is only to retrieve the data from the database,
* it should not process the returned data.
*
+ * @todo Cache just like get_field_defs, create new get_field_defs_live for ACP
* @param array $opts Optional custom SQL cmd/value pair attributes
* @return array An array of an array, outer key is field_id
*/
Modified: branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/main.php
===================================================================
--- branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/main.php 2008-02-13 19:06:25 UTC (rev 42)
+++ branches/stable_3_0_x/upload/sources/components_public/fusionscripts/fusionregistry/main.php 2008-02-14 09:01:47 UTC (rev 43)
@@ -65,6 +65,7 @@
var $nav_bar = array();
var $html = array( 'core', 'main', 'gallery', 'item' );
var $lib = array( 'custom_fields', 'content', 'functions', 'attach' );
+ var $cache = array( 'registry_field_defs', 'registry_stats' );
/**#@-*/
/** @var object Fusion Registry core */
@@ -283,31 +284,34 @@
) );
// Get our custom fields to be shown on the browse screen, if any
- $cf_defs = $this->lib['custom_fields']->get_cf_defs( array('WHERE' => "field_browse='1'", 'ORDER BY' => 'field_order ASC') );
+ $cf_defs = $this->lib['custom_fields']->get_cf_defs( array('WHERE' => array('field_browse' => 1),
+ 'ORDER BY' => array('field_order' => 'ASC') ) );
- // Create our sql id list, this will be used when retrieving the custom field entries
- $cf_ids = "'". implode( "','", array_keys($cf_defs) ) . "'";
+ if ( is_array($cf_defs) )
+ {
+ // Create our sql id list, this will be used when retrieving the custom field entries
+ $cf_ids = "'". implode( "','", array_keys($cf_defs) ) . "'";
- // Build our <th>'s for the custom fields
- $data['custom_field_th'] = '';
+ // Build our <th>'s for the custom fields
+ $data['custom_field_th'] = '';
- // How much width should each get? We're going to be nice and share equally :)
- // 48% is the amount left over from the static columns.
- $denom = count($cf_defs) ? count($cf_defs) : 1;
- $cf_width = 48 / $denom;
- $cf_width .= '%';
+ // How much width should each get? We're going to be nice and share equally :)
+ // 48% is the amount left over from the static columns.
+ $denom = count($cf_defs) ? count($cf_defs) : 1;
+ $cf_width = 48 / $denom;
+ $cf_width .= '%';
- // Loop through each one and add the <th> html to the output
- foreach ( $cf_defs as $cf_id => $cf_row )
- {
- $cf_data['field_name'] = $cf_row['field_name'];
- $cf_data['field_width'] = $cf_width;
+ // Loop through each one and add the <th> html to the output
+ foreach ( $cf_defs as $cf_id => $cf_row )
+ {
+ $cf_data['field_name'] = $cf_row['field_name'];
+ $cf_data['field_width'] = $cf_width;
- $data['custom_field_th'] .= $this->ipsclass->compiled_templates['skin_registry_main']->browse_th($cf_data);
+ $data['custom_field_th'] .= $this->ipsclass->compiled_templates['skin_registry_main']->browse_th($cf_data);
+ }
}
-
// Start building the query for the garage
$query = "SELECT g.id, g.image_id, g.member_id, g.views, g.date_updated,
g.date_created, m.members_display_name, count(mods.id) AS total_mods
@@ -329,24 +333,27 @@
while ( $row = $this->ipsclass->DB->fetch_row($outer_resource) )
{
// Get our custom fields data
- $cf_entries = $this->lib['custom_fields']->get_cf_entries( array( 'WHERE' => "item_id='".$row['id']."' AND field_id IN (".$cf_ids.")" ) );
+ if ( is_array($cf_defs) )
+ {
+ $cf_entries = $this->lib['custom_fields']->get_cf_entries( array( 'WHERE' => "item_id='".$row['id']."' AND field_id IN (".$cf_ids.")" ) );
- // Build our <td>'s for the custom fields
- $row['custom_fields'] = '';
+ // Build our <td>'s for the custom fields
+ $row['custom_fields'] = '';
- foreach ( $cf_defs as $cf_id => $cf_row )
- {
- // Which css class should we be? This isn't perfect, but will have to do.
- $cf_data['field_class'] = $total_cars_printed % 2 ? 'row2' : 'row1';
+ foreach ( $cf_defs as $cf_id => $cf_row )
+ {
+ // Which css class should we be? This isn't perfect, but will have to do.
+ $cf_data['field_class'] = $total_cars_printed % 2 ? 'row2' : 'row1';
- $cf_data['item_id'] = $row['id'];
+ $cf_data['item_id'] = $row['id'];
- $cf_data['field_value'] = $this->lib['custom_fields']->process_cf_value( array( 'def' => $cf_row,
- 'value' => $cf_entries[$cf_id]['field_value'],
- 'type' => 'view',
- ) );
+ $cf_data['field_value'] = $this->lib['custom_fields']->process_cf_value( array( 'def' => $cf_row,
+ 'value' => $cf_entries[$cf_id]['field_value'],
+ 'type' => 'view',
+ ) );
- $row['custom_fields'] .= $this->ipsclass->compiled_templates['skin_registry_main']->browse_td($cf_data);
+ $row['custom_fields'] .= $this->ipsclass->compiled_templates['skin_registry_main']->browse_td($cf_data);
+ }
}
// Make the dates human readable
@@ -496,7 +503,7 @@
}
// Grab all the defs that are searchable first
- $cf_defs = $this->lib['custom_fields']->get_cf_defs( array( 'WHERE' => "field_search='1'" ) );
+ $cf_defs = $this->lib['custom_fields']->get_cf_defs( array( 'WHERE' => array('field_search' => 1) ) );
// Process the custom fields input
$cf_input = $this->lib['custom_fields']->process_cf_input($cf_defs);
@@ -622,25 +629,23 @@
{
$data = array();
- // Get the total count of items and views in the garage
- $this->ipsclass->DB->query("SELECT count(*) AS total_items, SUM(views) AS total_views FROM ibf_registry_items");
- $row = $this->ipsclass->DB->fetch_row();
+ // Get the total count of items and views in the garage from cache
+ if ( isset( $this->ipsclass->cache['registry_stats'] ) &&
+ is_array( $this->ipsclass->cache['registry_stats'] ) )
+ {
+ $data['stats']['total_items'] = $this->ipsclass->cache['registry_stats']['total_items'];
+ $data['stats']['total_mods'] = $this->ipsclass->cache['registry_stats']['total_mods'];
+ $data['stats']['total_views'] = $this->ipsclass->cache['registry_stats']['total_views'];
+ $data['stats']['total_comments'] = $this->ipsclass->cache['registry_stats']['total_comments'];
+ }
+ else
+ {
+ $data['stats']['total_items'] = 0;
+ $data['stats']['total_mods'] = 0;
+ $data['stats']['total_views'] = 0;
+ $data['stats']['total_comments'] = 0;
+ }
- $data['stats']['total_items'] = $row['total_items'];
- $data['stats']['total_views'] = $row['total_views'];
-
- // Get the total count of mods in the garage
- $this->ipsclass->DB->query("SELECT count(*) AS total_mods FROM ibf_registry_mods");
- $row = $this->ipsclass->DB->fetch_row();
-
- $data['stats']['total_mods'] = $row['total_mods'];
-
- // Get the total count of comments in the garage
- $this->ipsclass->DB->query("SELECT count(*) AS total_comments FROM ibf_registry_guestbooks");
- $row = $this->ipsclass->DB->fetch_row();
-
- $data['stats']['total_comments'] = $row['total_comments'];
-
// Do we have a featured item?
if ( ($this->registry_config['enable_featured_item'] == 1) AND
( (empty($this->registry_config['featured_item_id']) === FALSE) OR ($this->registry_config['featured_item_random'] == 1) ) )
Modified: branches/stable_3_0_x/upload/sources/tasks/registrysessions.php
===================================================================
--- branches/stable_3_0_x/upload/sources/tasks/registrysessions.php 2008-02-13 19:06:25 UTC (rev 42)
+++ branches/stable_3_0_x/upload/sources/tasks/registrysessions.php 2008-02-14 09:01:47 UTC (rev 43)
@@ -45,6 +45,13 @@
exit();
}
+/**#@+
+ * Fusion Registry requires
+ */
+require( ROOT_PATH.'sources/components_public/fusion_config.php' );
+require( REGISTRY_PATH.'lib/functions.php' );
+/**#@-*/
+
/**
* Delete old Fusion Registry sessions
*
@@ -60,8 +67,10 @@
var $task = "";
/**#@-*/
- /** @var object */
+ /**#@+ @var object */
var $class = "";
+ var $fr_cache = "";
+ /**#@-*/
/** @var integer Fusion Registry sessions older than this # seconds will be deleted */
var $gc_maxlifetime = 1800;
@@ -79,8 +88,12 @@
// Bye-bye old sessions!
$this->ipsclass->DB->simple_exec_query( array( 'delete' => 'registry_sessions', 'where' => "ses_time < $date" ) );
+ $this->fr_cache = new registry_functions();
+ $this->fr_cache->ipsclass =& $this->ipsclass;
+ $this->fr_cache->update_stats_cache();
+
// Log to log table
- $this->class->append_task_log( $this->task, 'Old Fusion Registry sessions removed' );
+ $this->class->append_task_log( $this->task, 'Old Fusion Registry sessions removed, main menu stats recalculated' );
// Unlock Task: DO NOT MODIFY!
$this->class->unlock_task( $this->task );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|