diff --git a/include/class.cron.php b/include/class.cron.php
index 3aa0357c198ce61e25a22dae6bc9ea982954877e..390ff0769117001d0714cd9f9874da74ada59b90 100644
--- a/include/class.cron.php
+++ b/include/class.cron.php
@@ -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();
     }
 }
 ?>
diff --git a/include/class.lock.php b/include/class.lock.php
index bbf53b5498451c8ab6e3660282898fa3f4318eb4..d6bcbad9dc66105803fbb49a267252d068423242 100644
--- a/include/class.lock.php
+++ b/include/class.lock.php
@@ -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);
     }
 }
 ?>
diff --git a/include/class.ostsession.php b/include/class.ostsession.php
index 78b118299f2ceac11acc85206ab212740cb8079a..d27debae7a795859e7b37a0596e19516ee4aa1bc 100644
--- a/include/class.ostsession.php
+++ b/include/class.ostsession.php
@@ -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;
 
diff --git a/include/class.ticket.php b/include/class.ticket.php
index 7c816ff80cbcf6498d1e4925042141e15cab62dd..f32cfbd86d8f12eccb000c4707b54d159b068991 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -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;
     }
 
diff --git a/include/class.usersession.php b/include/class.usersession.php
index c24bb76ab85188829654cd6ba8b86fdd37d36d7d..e77f65fac77f63853cb3c6a4dea99d93e51ea491 100644
--- a/include/class.usersession.php
+++ b/include/class.usersession.php
@@ -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();
     }
 
diff --git a/scp/ajax.php b/scp/ajax.php
index bc6c920bc76e6fc2b5c4f93c9b3b5e96d7224e75..a5e56bd409c67381fcf2461dc627723d7a92460f 100644
--- a/scp/ajax.php
+++ b/scp/ajax.php
@@ -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.
diff --git a/scp/autocron.php b/scp/autocron.php
index ec7cb4c744b6b170da3d5186d09b59fc0e424342..1e2460786f13405b24139bb7e4ca6bddc363c579 100644
--- a/scp/autocron.php
+++ b/scp/autocron.php
@@ -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
diff --git a/scp/staff.inc.php b/scp/staff.inc.php
index 359663a4c6fccd04dc466126c759d71a89acb5a4..73fe46d3804b449966f0dc58cbda68308a8145fc 100644
--- a/scp/staff.inc.php
+++ b/scp/staff.inc.php
@@ -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