Bug #21017 » 0011903_v0.patch

Administrator Admin, 2009-09-08 18:43

View differences:

t3lib/config_default.php (Arbeitskopie)
123 123
				'cache_hash' => array(
124 124
					'backend' => 't3lib_cache_backend_DbBackend',
125 125
					'options' => array(
126
						'cacheTable' => 'cache_hash'
126
						'cacheTable' => 'cache_hash',
127
						'tagsTable' => 'cache_hash_tags',
127 128
					)
128 129
				),
129 130
				'cache_pages' => array(
130 131
					'backend' => 't3lib_cache_backend_DbBackend',
131 132
					'options' => array(
132
						'cacheTable' => 'cache_pages'
133
						'cacheTable' => 'cache_pages',
134
						'tagsTable' => 'cache_pages_tags',
133 135
					)
134 136
				),
135 137
				'cache_pagesection' => array(
136 138
					'backend' => 't3lib_cache_backend_DbBackend',
137 139
					'options' => array(
138
						'cacheTable' => 'cache_pagesection'
140
						'cacheTable' => 'cache_pagesection',
141
						'tagsTable' => 'cache_pagesection_tags',
139 142
					)
140 143
				)
141 144
				/*
t3lib/stddb/tables.sql (Arbeitskopie)
124 124
#
125 125
CREATE TABLE cache_hash (
126 126
  id int(11) unsigned NOT NULL auto_increment,
127
  identifier varchar(250) DEFAULT '' NOT NULL,
127
  identifier varchar(128) DEFAULT '' NOT NULL,
128 128
  crdate int(11) unsigned DEFAULT '0' NOT NULL,
129 129
  content mediumtext,
130
  tags mediumtext,
131 130
  lifetime int(11) unsigned DEFAULT '0' NOT NULL,
132 131
  PRIMARY KEY (id),
133 132
  KEY cache_id (identifier)
134 133
) ENGINE=InnoDB;
135 134

  
136 135
#
136
# Table structure for table 'cache_hash_tags'
137
#
138
CREATE TABLE cache_hash_tags (
139
  id int(11) unsigned NOT NULL auto_increment,
140
  identifier varchar(128) DEFAULT '' NOT NULL,
141
  tag varchar(128) DEFAULT '' NOT NULL,
142
  PRIMARY KEY (id),
143
  KEY cache_id (identifier),
144
  KEY cache_tag (tag)
145
) ENGINE=InnoDB;
146

  
147
#
137 148
# Table structure for table 'cache_imagesizes'
138 149
#
139 150
CREATE TABLE cache_imagesizes (
t3lib/cache/backend/class.t3lib_cache_backend_dbbackend.php (Arbeitskopie)
33 33
class t3lib_cache_backend_DbBackend extends t3lib_cache_backend_AbstractBackend {
34 34

  
35 35
	protected $cacheTable;
36
	protected $tagsTable;
36 37

  
37 38
	/**
38 39
	 * Saves data in a cache file.
......
73 74
				'identifier' => $entryIdentifier,
74 75
				'crdate'     => $GLOBALS['EXEC_TIME'],
75 76
				'content'    => $data,
76
				'tags'       => implode(',', $tags),
77 77
				'lifetime'   => $lifetime
78 78
			)
79 79
		);
80

  
81
		foreach ($tags as $tag) {
82
			$GLOBALS['TYPO3_DB']->exec_INSERTquery(
83
				$this->tagsTable,
84
				array(
85
					'identifier' => $entryIdentifier,
86
					'tag'        => $tag,
87
				)
88
			);
89
		}
80 90
	}
81 91

  
82 92
	/**
......
138 148
	public function remove($entryIdentifier) {
139 149
		$entryRemoved = false;
140 150

  
151
		$GLOBALS['TYPO3_DB']->exec_DELETEquery(
152
			$this->tagsTable,
153
			'identifier = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($entryIdentifier, $this->tagsTable)
154
		);
155

  
141 156
		$res = $GLOBALS['TYPO3_DB']->exec_DELETEquery(
142 157
			$this->cacheTable,
143 158
			'identifier = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($entryIdentifier, $this->cacheTable)
......
161 176
		$cacheEntryIdentifiers = array();
162 177

  
163 178
		$cacheEntryIdentifierRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
164
			'identifier',
165
			$this->cacheTable,
166
			$this->getListQueryForTag($tag) . ' AND (crdate + lifetime >= ' . $GLOBALS['EXEC_TIME'] . ' OR lifetime = 0)'
179
			$this->cacheTable . '.identifier',
180
			$this->cacheTable . ', ' . $this->tagsTable,
181
			$this->getQueryForTag() .
182
				' AND ' . $this->cacheTable . '.identifier = ' . $this->tagsTable . '.identifier' .
183
				' AND (crdate + lifetime >= ' . $GLOBALS['EXEC_TIME'] . ' OR lifetime = 0)',
184
			$this->cacheTable . '.identifier'
167 185
		);
168 186

  
169 187
		foreach ($cacheEntryIdentifierRows as $cacheEntryIdentifierRow) {
......
186 204
		$whereClause  = array();
187 205

  
188 206
		foreach ($tags as $tag) {
189
			$whereClause[] = $this->getListQueryForTag($tag);
207
			$whereClause[] = $this->getQueryForTag($tag);
190 208
		}
209

  
210
		$whereClause[] = $this->cacheTable . '.identifier = ' . $this->tagsTable . '.identifier';
191 211
		$whereClause[] = '(crdate + lifetime >= ' . $GLOBALS['EXEC_TIME'] . ' OR lifetime = 0)';
192 212

  
193 213
		$cacheEntryIdentifierRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
194
			'identifier',
195
			$this->cacheTable,
196
			implode(' AND ', $whereClause)
214
			$this->cacheTable . 'identifier',
215
			$this->cacheTable . ', ' . $this->tagsTable,
216
			implode(' AND ', $whereClause),
217
			$this->cacheTable . '.identifier'
197 218
		);
198 219

  
199 220
		foreach ($cacheEntryIdentifierRows as $cacheEntryIdentifierRow) {
......
211 232
	 */
212 233
	public function flush() {
213 234
		$GLOBALS['TYPO3_DB']->sql_query('TRUNCATE ' . $this->cacheTable);
235
		$GLOBALS['TYPO3_DB']->sql_query('TRUNCATE ' . $this->tagsTable);
214 236
	}
215 237

  
216 238
	/**
......
220 242
	 * @return void
221 243
	 */
222 244
	public function flushByTag($tag) {
223
		$GLOBALS['TYPO3_DB']->exec_DELETEquery(
224
			$this->cacheTable,
225
			$this->getListQueryForTag($tag)
226
		);
245
		// @todo: DELETE FROM cacheTable, tagsTable USING cacheTable INNER JOIN tagsTable... would be nice - but TYPO3_DB does not support it
246
		foreach ($this->findIdentifiersByTag($tag) as $entryIdentifier) {
247
			$this->remove($entryIdentifier);
248
		}
227 249
	}
228 250

  
229 251
	/**
......
233 255
	 * @return void
234 256
	 */
235 257
	public function flushByTags(array $tags) {
236
		$listQueryConditions = array();
237
		foreach ($tags as $tag) {
238
			$listQueryConditions[$tag] = $this->getListQueryForTag($tag);
258
		// @todo: DELETE FROM cacheTable, tagsTable USING cacheTable INNER JOIN tagsTable... would be nice - but TYPO3_DB does not support it
259
		foreach ($this->findIdentifiersByTags($tags) as $entryIdentifier) {
260
			$this->remove($entryIdentifier);
239 261
		}
240

  
241
		$listQuery = implode(' OR ', $listQueryConditions);
242
		$GLOBALS['TYPO3_DB']->exec_DELETEquery(
243
			$this->cacheTable,
244
			$listQuery
245
		);
246 262
	}
247 263

  
248 264
	/**
......
252 268
	 * @author Ingo Renner <ingo@typo3.org>
253 269
	 */
254 270
	public function collectGarbage() {
255
		$GLOBALS['TYPO3_DB']->exec_DELETEquery(
256
			$this->cacheTable,
271
		// @todo: DELETE FROM cacheTable, tagsTable USING cacheTable INNER JOIN tagsTable... would be nice - but TYPO3_DB does not support it
272
		// Alternative here: Add lifetime to tagsTable as well...
273
		$cacheEntryIdentifierRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
274
			'identifier',
257 275
			'crdate + lifetime < ' . $GLOBALS['EXEC_TIME'] . ' AND lifetime > 0'
258 276
		);
277

  
278
		foreach ($cacheEntryIdentifierRows as $cacheEntryIdentifierRow) {
279
			$this->remove($cacheEntryIdentifierRow['identifier']);
280
		}
259 281
	}
260 282

  
261 283
	/**
......
313 335
	}
314 336

  
315 337
	/**
338
	 * Sets the table where cache tags are stored.
339
	 *
340
	 * @param	string		$tagsTabls: Name of the table
341
	 * @return	void
342
	 */
343
	public function setTagsTable($tagsTable) {
344
		$this->tagsTable = $tagsTable;
345
	}
346

  
347
	/**
348
	 * Gets the table where cache tags are store.
349
	 *
350
	 * @return	string		Name of the table storing tags
351
	 */
352
	public function getTagsTable() {
353
		return $this->tagsTable;
354
	}
355

  
356
	/**
316 357
	 * Gets the query to be used for selecting entries by a tag. The asterisk ("*")
317 358
	 * is allowed as a wildcard at the beginning and the end of a tag.
318 359
	 *
......
320 361
	 * @return string the query to be used for selecting entries
321 362
	 * @author Oliver Hader <oliver@typo3.org>
322 363
	 */
323
	protected function getListQueryForTag($tag) {
324
		return str_replace('*', '%', $GLOBALS['TYPO3_DB']->listQuery('tags', $tag, $this->cacheTable));
364
	protected function getQueryForTag($tag) {
365
		if (strpos($tag, '*') === false) {
366
			$query = $this->tagsTable . 'tag = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($tag, $this->tagsTable);
367
		} else {
368
			$patternForLike = $GLOBALS['TYPO3_DB']->escapeStrForLike(
369
				$GLOBALS['TYPO3_DB']->quoteStr($tag, $this->tagsTable),
370
				$this->tagsTable
371
			);
372
			$query = $this->tagsTable . 'tag LIKE \'' . $patternForLike . '\'';
373
		}
374

  
375
		return $query;
325 376
	}
326 377
}
327 378

  
typo3/sysext/cms/ext_tables.sql (Arbeitskopie)
8 8
#
9 9
CREATE TABLE cache_pages (
10 10
  id int(11) unsigned NOT NULL auto_increment,
11
  identifier varchar(250) DEFAULT '' NOT NULL,
11
  identifier varchar(128) DEFAULT '' NOT NULL,
12 12
  crdate int(11) unsigned DEFAULT '0' NOT NULL,
13 13
  content mediumtext,
14
  tags mediumtext,
15 14
  lifetime int(11) unsigned DEFAULT '0' NOT NULL,
16 15
  PRIMARY KEY (id),
17 16
  KEY cache_id (identifier)
......
19 18

  
20 19

  
21 20
#
21
# Table structure for table 'cache_pages_tags'
22
#
23
CREATE TABLE cache_pages_tags (
24
  id int(11) unsigned NOT NULL auto_increment,
25
  identifier varchar(128) DEFAULT '' NOT NULL,
26
  tag varchar(128) DEFAULT '' NOT NULL,
27
  PRIMARY KEY (id),
28
  KEY cache_id (identifier),
29
  KEY cache_tag (tag)
30
) ENGINE=InnoDB;
31

  
32

  
33
#
22 34
# Table structure for table 'cache_pagesection'
23 35
#
24 36
CREATE TABLE cache_pagesection (
25 37
  id int(11) unsigned NOT NULL auto_increment,
26
  identifier varchar(250) DEFAULT '' NOT NULL,
38
  identifier varchar(128) DEFAULT '' NOT NULL,
27 39
  crdate int(11) unsigned DEFAULT '0' NOT NULL,
28 40
  content mediumtext,
29
  tags mediumtext,
30 41
  lifetime int(11) unsigned DEFAULT '0' NOT NULL,
31 42
  PRIMARY KEY (id),
32 43
  KEY cache_id (identifier)
......
34 45

  
35 46

  
36 47
#
48
# Table structure for table 'cache_pagesection_tags'
49
#
50
CREATE TABLE cache_pagesection_tags (
51
  id int(11) unsigned NOT NULL auto_increment,
52
  identifier varchar(128) DEFAULT '' NOT NULL,
53
  tag varchar(128) DEFAULT '' NOT NULL,
54
  PRIMARY KEY (id),
55
  KEY cache_id (identifier),
56
  KEY cache_tag (tag)
57
) ENGINE=InnoDB;
58

  
59

  
60
#
37 61
# Table structure for table 'cache_typo3temp_log'
38 62
#
39 63
CREATE TABLE cache_typo3temp_log (
(1-1/5)