|
From: <rgr...@us...> - 2014-01-23 17:39:02
|
Revision: 12273
http://sourceforge.net/p/xoops/svn/12273
Author: rgriffith
Date: 2014-01-23 17:39:00 +0000 (Thu, 23 Jan 2014)
Log Message:
-----------
Partial fix to #1268 - reduce db load if XoopsFormSelectUser is called multiple times in a page load
Modified Paths:
--------------
XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formselectuser.php
Modified: XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formselectuser.php
===================================================================
--- XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formselectuser.php 2014-01-23 15:01:19 UTC (rev 12272)
+++ XoopsCore/branches/2.5.x/2.5.7/htdocs/class/xoopsform/formselectuser.php 2014-01-23 17:39:00 UTC (rev 12273)
@@ -42,23 +42,47 @@
*/
function XoopsFormSelectUser($caption, $name, $include_anon = false, $value = null, $size = 1, $multiple = false)
{
- $limit = 200;
+ /**
+ * @var array|null - cache potentially expensive result for this session.
+ * Some modules use multiple copies of this element on a single page, and for
+ * sites with large user bases, that can be quite expensive when $value is null.
+ * @todo this should be replaced with a filter or autocomplete interface .
+ */
+ static $querycache = null;
+ /**
+ * @var int|null - cache record count from member_handler
+ */
+ static $countcache = null;
+
+ $limit = 100;
$select_element = new XoopsFormSelect('', $name, $value, $size, $multiple);
if ($include_anon) {
$select_element->addOption(0, $GLOBALS['xoopsConfig']['anonymous']);
}
$member_handler =& xoops_gethandler('member');
- $user_count = $member_handler->getUserCount();
+ if ($countcache===null) {
+ $countcache = $member_handler->getUserCount();
+ }
+ $user_count = $countcache;
$value = is_array($value) ? $value : (empty($value) ? array() : array($value));
if ($user_count > $limit && count($value) > 0) {
$criteria = new CriteriaCompo(new Criteria('uid', '(' . implode(',', $value) . ')', 'IN'));
+ $use_cache = false;
} else {
+ $use_cache = true;
$criteria = new CriteriaCompo();
$criteria->setLimit($limit);
}
$criteria->setSort('uname');
$criteria->setOrder('ASC');
- $users = $member_handler->getUserList($criteria);
+ if ($use_cache && !empty($querycache)) {
+ $users = $querycache;
+ } else {
+ $users = $member_handler->getUserList($criteria);
+ if ($use_cache) {
+ $querycache = $users;
+ }
+ }
$select_element->addOptionArray($users);
if ($user_count <= $limit) {
$this->XoopsFormElementTray($caption, "", $name);
|