- 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
| | |
| | | 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
|
| | |
| | |
|
| | | 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
|
| | |
| | | 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
|
| | |
| | | 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, |
| | |
| | | -- 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`); |
| | |
| | | |
| | | 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, |
| | |
| | | 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; |
| | |
| | | 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" |
| | |
| | | |
| | | -- 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); |
| | |
| | | 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 |
| | |
| | | { |
| | | $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); |
| | | } |
| | |
| | | { |
| | | $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); |
| | | } |
| | | } |
| | | |
| | |
| | | $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, |
| | |
| | | |
| | | $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; |
| | | } |
| | | |
| | |
| | | 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') . " |