Skip to content

Commit

Permalink
Update sessions table for accuracy/efficiency
Browse files Browse the repository at this point in the history
- changed id to case-sensitive ascii (some PHP configurations use letter
  casing to distinguish different sessions)
- added index on modified, for more efficient gc
- updated gc to make an index-compatible query
  • Loading branch information
zerocrates committed Jul 14, 2024
1 parent b51ce67 commit c4c3c32
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
16 changes: 16 additions & 0 deletions application/libraries/Omeka/Session/SaveHandler/DbTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,20 @@ public function write($id, $data)
// Discard parent's return value and return true (PHP 7 actually cares about this)
return true;
}

/**
* Garbage Collection
*
* Overrides Zend's gc to always use the same lifetime rather than the stored column
*
* @param int $maxlifetime
* @return true
*/
public function gc($maxlifetime)
{
$this->delete($this->getAdapter()->quoteIdentifier($this->_modifiedColumn, true) . ' < '
. $this->getAdapter()->quote(time() - $this->_lifetime));

return true;
}
}
20 changes: 20 additions & 0 deletions application/migrations/20240713211400_updateSessionsTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Omeka
*
* @copyright Copyright 2007-2020 Roy Rosenzweig Center for History and New Media
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU GPLv3
*/

/**
* Change sessions table to case-sensitive ascii IDs and add index on modified column
*
* @package Omeka\Db\Migration
*/
class updateSessionsTable extends Omeka_Db_Migration_AbstractMigration
{
public function up()
{
$this->db->query("ALTER TABLE {$this->db->Session} MODIFY `id` varchar(128) collate ascii_bin, ADD INDEX `modified` (`modified`)");
}
}
5 changes: 3 additions & 2 deletions application/schema/sessions.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
CREATE TABLE IF NOT EXISTS `%PREFIX%sessions` (
`id` varchar(128),
`id` varchar(128) collate ascii_bin,
`modified` bigint,
`lifetime` int,
`data` blob,
PRIMARY KEY (`id`)
PRIMARY KEY (`id`),
KEY `modified` (`modified`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
2 changes: 1 addition & 1 deletion bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

// Define the current version of Omeka.
define('OMEKA_VERSION', '3.2-dev');
define('OMEKA_VERSION', '3.2-dev2');

// Define the application environment.
if (!defined('APPLICATION_ENV')) {
Expand Down

0 comments on commit c4c3c32

Please sign in to comment.