diff options
author | alecpl <alec@alec.pl> | 2008-11-22 18:06:13 +0000 |
---|---|---|
committer | alecpl <alec@alec.pl> | 2008-11-22 18:06:13 +0000 |
commit | dcf780a6bd5065ffb0dcc76233b1e5f601e258d2 (patch) | |
tree | f1e127b3cf04f18cf3776af057edd4fa57ec36e1 | |
parent | 3e48d2eee1d2af42aa777fd5e461fa570762732e (diff) |
- 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
-rw-r--r-- | SQL/mssql.initial.sql | 5 | ||||
-rw-r--r-- | SQL/mysql.initial.sql | 1 | ||||
-rw-r--r-- | SQL/mysql.update.sql | 7 | ||||
-rw-r--r-- | SQL/mysql5.initial.sql | 5 | ||||
-rw-r--r-- | SQL/postgres.initial.sql | 2 | ||||
-rw-r--r-- | SQL/postgres.update.sql | 4 | ||||
-rw-r--r-- | SQL/sqlite.initial.sql | 1 | ||||
-rw-r--r-- | program/include/rcube_imap.php | 12 | ||||
-rw-r--r-- | program/include/session.inc | 34 |
9 files changed, 9 insertions, 62 deletions
diff --git a/SQL/mssql.initial.sql b/SQL/mssql.initial.sql index fc60a4d8d..162495781 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 @@ GO 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
@@ -130,9 +128,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
CONSTRAINT [DF_contacts_user_id] DEFAULT (0) FOR [user_id],
CONSTRAINT [DF_contacts_changed] DEFAULT (getdate()) FOR [changed],
diff --git a/SQL/mysql.initial.sql b/SQL/mysql.initial.sql index 07f127cce..0f9fc8b92 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 a45ace1fd..1e8979d87 100644 --- a/SQL/mysql.update.sql +++ b/SQL/mysql.update.sql @@ -34,10 +34,7 @@ ALTER TABLE `messages` -- 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 7d11288e3..b162e4ddf 100644 --- a/SQL/mysql5.initial.sql +++ b/SQL/mysql5.initial.sql @@ -68,7 +68,6 @@ CREATE TABLE `messages` ( 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, @@ -78,10 +77,6 @@ CREATE TABLE `cache` ( 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 128b484d7..9fb8d32fb 100644 --- a/SQL/postgres.initial.sql +++ b/SQL/postgres.initial.sql @@ -129,14 +129,12 @@ CREATE SEQUENCE cache_ids 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 f9cd431b6..6832b962f 100644 --- a/SQL/postgres.update.sql +++ b/SQL/postgres.update.sql @@ -24,8 +24,6 @@ CREATE INDEX messages_created_idx ON messages (created); -- 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 d09539d6f..e78ce42b5 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 c3d599180..682686973 100644 --- a/program/include/rcube_imap.php +++ b/program/include/rcube_imap.php @@ -2146,11 +2146,10 @@ class rcube_imap { $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 @@ class rcube_imap { $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 @@ class rcube_imap $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 21d22ab28..3f01fcd53 100644 --- a/program/include/session.inc +++ b/program/include/session.inc @@ -111,12 +111,6 @@ function rcube_sess_destroy($key) $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 @@ function rcube_sess_gc($maxlifetime) 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') . " |