Skip to content
Browse files

- fix r2076: removed cache.session_id column, removed DELETEs from ca…

…che in session_gc

- trust DB server's time when "touching" cache and messages tables
  • Loading branch information...
1 parent 3e48d2e commit dcf780a6bd5065ffb0dcc76233b1e5f601e258d2 @alecpl alecpl committed Nov 22, 2008
View
5 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],
View
1 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,
View
7 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`);
View
5 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;
View
2 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"
View
4 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);
View
1 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
View
12 program/include/rcube_imap.php
@@ -2146,11 +2146,10 @@ function _write_cache_record($key, $data)
{
$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 @@ function _write_cache_record($key, $data)
{
$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 @@ function add_message_cache($key, $index, $headers, $struct=null)
$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,
View
34 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') . "

0 comments on commit dcf780a

Please sign in to comment.
Something went wrong with that request. Please try again.