Skip to content
Snippets Groups Projects
Commit a94ef000 authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge pull request #415 from greezybacon/db-perf-tweaks


Several database performance tweaks

Reviewed-By: default avatarPeter Rotich <peter@osticket.com>
parents ea7b8b5e 268e26ea
Branches
Tags
No related merge requests found
......@@ -32,7 +32,9 @@ class Cron {
function PurgeLogs() {
global $ost;
if($ost) $ost->purgeLogs();
// Once a day on a 5-minute cron
if (rand(1,300) == 42)
if($ost) $ost->purgeLogs();
}
function PurgeDrafts() {
......@@ -45,6 +47,47 @@ class Cron {
AttachmentFile::deleteOrphans();
}
function MaybeOptimizeTables() {
// Once a week on a 5-minute cron
$chance = rand(1,2000);
switch ($chance) {
case 42:
@db_query('OPTIMIZE TABLE '.TICKET_LOCK_TABLE);
break;
case 242:
@db_query('OPTIMIZE TABLE '.SYSLOG_TABLE);
break;
case 442:
@db_query('OPTIMIZE TABLE '.DRAFT_TABLE);
break;
// Start optimizing core ticket tables when we have an archiving
// system available
case 142:
#@db_query('OPTIMIZE TABLE '.TICKET_TABLE);
break;
case 542:
#@db_query('OPTIMIZE TABLE '.FORM_ENTRY_TABLE);
break;
case 642:
#@db_query('OPTIMIZE TABLE '.FORM_ANSWER_TABLE);
break;
case 342:
#@db_query('OPTIMIZE TABLE '.FILE_TABLE);
# XXX: Please do not add an OPTIMIZE for the file_chunk table!
break;
// Start optimizing user tables when we have a user directory
// sporting deletes
case 742:
#@db_query('OPTIMIZE TABLE '.USER_TABLE);
break;
case 842:
#@db_query('OPTIMIZE TABLE '.USER_EMAIL_TABLE);
break;
}
}
function run(){ //called by outside cron NOT autocron
global $ost;
if (!$ost || $ost->isUpgradePending())
......@@ -55,6 +98,7 @@ class Cron {
self::PurgeLogs();
self::CleanOrphanedFiles();
self::PurgeDrafts();
self::MaybeOptimizeTables();
}
}
?>
......@@ -147,11 +147,10 @@ class TicketLock {
return db_query($sql);
}
//Called via cron
//Called via cron
function cleanup() {
//Cleanup any expired locks.
db_query('DELETE FROM '.TICKET_LOCK_TABLE.' WHERE expire<NOW()');
@db_query('OPTIMIZE TABLE '.TICKET_LOCK_TABLE);
}
}
?>
......@@ -18,6 +18,7 @@ class osTicketSession {
var $ttl = SESSION_TTL;
var $data = '';
var $data_hash = '';
var $id = '';
function osTicketSession($ttl=0){
......@@ -87,12 +88,16 @@ class osTicketSession {
list($this->data)=db_fetch_row($res);
$this->id = $id;
}
$this->data_hash = md5($this->data);
return $this->data;
}
function write($id, $data){
global $thisstaff;
if (md5($data) == $this->data_hash)
return;
$ttl = ($this && get_class($this) == 'osTicketSession')
? $this->getTTL() : SESSION_TTL;
......
......@@ -98,9 +98,6 @@ class Ticket {
$this->topic = null;
$this->thread = null;
//REQUIRED: Preload thread obj - checked on lookup!
$this->getThread();
return true;
}
......@@ -1788,8 +1785,7 @@ class Ticket {
return ($id
&& is_numeric($id)
&& ($ticket= new Ticket($id))
&& $ticket->getId()==$id
&& $ticket->getThread())
&& $ticket->getId()==$id)
?$ticket:null;
}
......
......@@ -66,6 +66,14 @@ class UserSession {
return($token);
}
function getLastUpdate($htoken) {
if (!$htoken)
return 0;
@list($hash,$expire,$ip)=explode(":",$htoken);
return $expire;
}
function isvalidSession($htoken,$maxidletime=0,$checkip=false){
global $cfg;
......@@ -122,7 +130,10 @@ class ClientSession extends Client {
}
function refreshSession(){
global $_SESSION;
$time = $this->session->getLastUpdate($_SESSION['_client']['token']);
// Deadband session token updates to once / 30-seconds
if (time() - $time < 30)
return;
$_SESSION['_client']['token']=$this->getSessionToken();
//TODO: separate expire time from hash??
}
......@@ -160,7 +171,11 @@ class StaffSession extends Staff {
}
function refreshSession(){
global $_SESSION;
$time = $this->session->getLastUpdate($_SESSION['_staff']['token']);
// Deadband session token updates to once / 30-seconds
if (time() - $time < 30)
return;
$_SESSION['_staff']['token']=$this->getSessionToken();
}
......
......@@ -21,6 +21,7 @@ function staffLoginPage($msg='Unauthorized') {
exit;
}
define('AJAX_REQUEST', 1);
require('staff.inc.php');
//Clean house...don't let the world see your crap.
......
......@@ -14,6 +14,7 @@
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
define('AJAX_REQUEST', 1);
require('staff.inc.php');
ignore_user_abort(1);//Leave me a lone bro!
@set_time_limit(0); //useless when safe_mode is on
......
......@@ -123,7 +123,9 @@ if($ost->isUpgradePending() && !$exempt) {
$sysnotice.=' <a href="settings.php">Enable</a>.';
}
$nav = new StaffNav($thisstaff);
if (!defined('AJAX_REQUEST'))
$nav = new StaffNav($thisstaff);
//Check for forced password change.
if($thisstaff->forcePasswdChange() && !$exempt) {
# XXX: Call staffLoginPage() for AJAX and API requests _not_ to honor
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment