From dcf780a6bd5065ffb0dcc76233b1e5f601e258d2 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Sat, 22 Nov 2008 13:06:13 -0500
Subject: [PATCH] - fix r2076: removed cache.session_id column, removed DELETEs from cache in session_gc - trust DB server's time when "touching" cache and messages tables
---
program/include/session.inc | 34 ----------------
program/include/rcube_imap.php | 12 ++---
SQL/mysql5.initial.sql | 5 --
SQL/postgres.update.sql | 4 -
SQL/mysql.update.sql | 7 +--
SQL/postgres.initial.sql | 2 -
SQL/mysql.initial.sql | 1
SQL/sqlite.initial.sql | 1
SQL/mssql.initial.sql | 5 --
9 files changed, 9 insertions(+), 62 deletions(-)
diff --git a/SQL/mssql.initial.sql b/SQL/mssql.initial.sql
index fc60a4d..1624957 100644
--- a/SQL/mssql.initial.sql
+++ b/SQL/mssql.initial.sql
@@ -1,7 +1,6 @@
CREATE TABLE [dbo].[cache] (
[cache_id] [int] IDENTITY (1, 1) NOT NULL ,
[user_id] [int] NOT NULL ,
- [session_id] [varchar] (32) COLLATE Latin1_General_CI_AI NULL ,
[cache_key] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
[created] [datetime] NOT NULL ,
[data] [text] COLLATE Latin1_General_CI_AI NOT NULL
@@ -119,7 +118,6 @@
ALTER TABLE [dbo].[cache] ADD
CONSTRAINT [DF_cache_user_id] DEFAULT ('0') FOR [user_id],
- CONSTRAINT [DF_cache_session_id] DEFAULT (null) FOR [session_id],
CONSTRAINT [DF_cache_cache_key] DEFAULT ('') FOR [cache_key],
CONSTRAINT [DF_cache_created] DEFAULT (getdate()) FOR [created]
GO
@@ -128,9 +126,6 @@
GO
CREATE INDEX [IX_cache_cache_key] ON [dbo].[cache]([cache_key]) ON [PRIMARY]
-GO
-
- CREATE INDEX [IX_cache_session_id] ON [dbo].[cache]([session_id]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[contacts] ADD
diff --git a/SQL/mysql.initial.sql b/SQL/mysql.initial.sql
index 07f127c..0f9fc8b 100644
--- a/SQL/mysql.initial.sql
+++ b/SQL/mysql.initial.sql
@@ -11,7 +11,6 @@
CREATE TABLE `cache` (
`cache_id` int(10) unsigned NOT NULL auto_increment,
`user_id` int(10) unsigned NOT NULL default '0',
- `session_id` varchar(40) default NULL,
`cache_key` varchar(128) NOT NULL default '',
`created` datetime NOT NULL default '0000-00-00 00:00:00',
`data` longtext NOT NULL,
diff --git a/SQL/mysql.update.sql b/SQL/mysql.update.sql
index a45ace1..1e8979d 100644
--- a/SQL/mysql.update.sql
+++ b/SQL/mysql.update.sql
@@ -34,10 +34,7 @@
-- Updates from version 0.2-beta (InnoDB only)
ALTER TABLE `cache`
- ADD CONSTRAINT `session_id_fk_cache` FOREIGN KEY (`session_id`)
- REFERENCES `session`(`sess_id`)
- ON DELETE CASCADE
- ON UPDATE CASCADE;
-
+ DROP `session_id`;
+
ALTER TABLE `session`
ADD INDEX `changed_index` (`changed`);
diff --git a/SQL/mysql5.initial.sql b/SQL/mysql5.initial.sql
index 7d11288..b162e4d 100644
--- a/SQL/mysql5.initial.sql
+++ b/SQL/mysql5.initial.sql
@@ -68,7 +68,6 @@
CREATE TABLE `cache` (
`cache_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
- `session_id` varchar(40) CHARACTER SET ascii COLLATE ascii_general_ci,
`cache_key` varchar(128) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`data` longtext NOT NULL,
@@ -77,10 +76,6 @@
INDEX `user_cache_index` (`user_id`,`cache_key`),
CONSTRAINT `user_id_fk_cache` FOREIGN KEY (`user_id`)
REFERENCES `users`(`user_id`)
- ON DELETE CASCADE
- ON UPDATE CASCADE,
- CONSTRAINT `session_id_fk_cache` FOREIGN KEY (`session_id`)
- REFERENCES `session`(`sess_id`)
ON DELETE CASCADE
ON UPDATE CASCADE
) TYPE=INNODB CHARACTER SET utf8 COLLATE utf8_general_ci;
diff --git a/SQL/postgres.initial.sql b/SQL/postgres.initial.sql
index 128b484..9fb8d32 100644
--- a/SQL/postgres.initial.sql
+++ b/SQL/postgres.initial.sql
@@ -129,14 +129,12 @@
CREATE TABLE "cache" (
cache_id integer DEFAULT nextval('cache_ids'::text) PRIMARY KEY,
user_id integer NOT NULL REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
- session_id character varying(40) REFERENCES "session" (sess_id) ON DELETE CASCADE ON UPDATE CASCADE,
cache_key character varying(128) DEFAULT ''::character varying NOT NULL,
created timestamp with time zone DEFAULT now() NOT NULL,
data text NOT NULL
);
CREATE INDEX cache_user_id_idx ON "cache" (user_id, cache_key);
-CREATE INDEX cache_session_id_idx ON "cache" (session_id);
--
-- Sequence "message_ids"
diff --git a/SQL/postgres.update.sql b/SQL/postgres.update.sql
index f9cd431..6832b96 100644
--- a/SQL/postgres.update.sql
+++ b/SQL/postgres.update.sql
@@ -24,8 +24,6 @@
-- Updates from version 0.2-beta
-ALTER TABLE cache DROP CONSTRAINT cache_session_id_fkey;
-ALTER TABLE cache ADD FOREIGN KEY (session_id) REFERENCES session (sess_id) ON DELETE CASCADE ON UPDATE CASCADE;
+ALTER TABLE cache DROP session_id;
-CREATE INDEX cache_session_id_idx ON cache (session_id);
CREATE INDEX session_changed_idx ON session (changed);
diff --git a/SQL/sqlite.initial.sql b/SQL/sqlite.initial.sql
index d09539d..e78ce42 100644
--- a/SQL/sqlite.initial.sql
+++ b/SQL/sqlite.initial.sql
@@ -11,7 +11,6 @@
CREATE TABLE cache (
cache_id integer NOT NULL PRIMARY KEY,
user_id integer NOT NULL default 0,
- session_id varchar(40) default NULL,
cache_key varchar(128) NOT NULL default '',
created datetime NOT NULL default '0000-00-00 00:00:00',
data longtext NOT NULL
diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index c3d5991..6826869 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -2146,11 +2146,10 @@
{
$this->db->query(
"UPDATE ".get_table_name('cache')."
- SET created=". $this->db->fromunixtime(time()).", data=?, session_id=?
+ SET created=". $this->db->now().", data=?
WHERE user_id=?
AND cache_key=?",
$data,
- session_id(),
$_SESSION['user_id'],
$key);
}
@@ -2159,12 +2158,11 @@
{
$this->db->query(
"INSERT INTO ".get_table_name('cache')."
- (created, user_id, cache_key, data, session_id)
- VALUES (".$this->db->fromunixtime(time()).", ?, ?, ?, ?)",
+ (created, user_id, cache_key, data)
+ VALUES (".$this->db->now().", ?, ?, ?)",
$_SESSION['user_id'],
$key,
- $data,
- session_id());
+ $data);
}
}
@@ -2374,7 +2372,7 @@
$this->db->query(
"INSERT INTO ".get_table_name('messages')."
(user_id, del, cache_key, created, idx, uid, subject, ".$this->db->quoteIdentifier('from').", ".$this->db->quoteIdentifier('to').", cc, date, size, headers, structure)
- VALUES (?, 0, ?, ".$this->db->fromunixtime(time()).", ?, ?, ?, ?, ?, ?, ".$this->db->fromunixtime($headers->timestamp).", ?, ?, ?)",
+ VALUES (?, 0, ?, ".$this->db->now().", ?, ?, ?, ?, ?, ?, ".$this->db->fromunixtime($headers->timestamp).", ?, ?, ?)",
$_SESSION['user_id'],
$key,
$index,
diff --git a/program/include/session.inc b/program/include/session.inc
index 21d22ab..3f01fcd 100644
--- a/program/include/session.inc
+++ b/program/include/session.inc
@@ -111,12 +111,6 @@
$DB->query("DELETE FROM " . get_table_name('session') . " WHERE sess_id=?", $key);
- // delete session entries in cache table
- // on databases wthout foreign keys
- if ($rcmail->config->get('enable_caching') && $DB->db_provider != 'pgsql') {
- $DB->query("DELETE FROM " . get_table_name('cache') . " WHERE session_id=?", $key);
- }
-
return true;
}
@@ -131,34 +125,8 @@
return false;
}
- $now = $DB->fromunixtime(time() - $maxlifetime);
-
- // delete session entries in cache table
- if ($rcmail->config->get('enable_caching')) {
-
- // on databases wthout foreign keys...
- if($DB->db_provider != 'pgsql') {
-
- // get all expired sessions
- $sql_result = $DB->query(
- "SELECT sess_id FROM " . get_table_name('session') . "
- WHERE changed < " . $now);
-
- $exp_sessions = array();
- while ($sql_arr = $DB->fetch_assoc($sql_result)) {
- $exp_sessions[] = $sql_arr['sess_id'];
- }
-
- if (sizeof($exp_sessions)) {
- $exp_sessions = "'" . join("','", $exp_sessions) . "'";
- // delete session cache records
- $DB->query("DELETE FROM " . get_table_name('cache') . "
- WHERE session_id IN (" . $exp_sessions . ")");
- }
- }
- // also run message cache GC
+ if ($rcmail->config->get('enable_caching'))
rcmail_message_cache_gc();
- }
// just delete all expired sessions
$DB->query("DELETE FROM " . get_table_name('session') . "
--
Gitblit v1.9.1