Просмотр исходного кода

MySQL : changements mineurs de types

D'autres changements de types, toujours sans modification de
comportement, mais plus efficace.
En particulier char(6) plutôt que varchar(6) pour les identifiants en
attendant un entier, et varchar plutôt que text dans des champs
généralement courts et souvent retournés par les requêtes les plus
importantes
Alexandre Alapetite 12 лет назад
Родитель
Сommit
5af7c472ed
3 измененных файлов с 28 добавлено и 28 удалено
  1. 11 11
      app/models/Entry.php
  2. 4 4
      app/models/Feed.php
  3. 13 13
      public/install.php

+ 11 - 11
app/models/Entry.php

@@ -179,16 +179,16 @@ class Entry extends Model {
 	public function toArray () {
 		return array (
 			'id' => $this->id (),
-			'guid' => substr($this->guid (), 0, 65535),
-			'title' => substr($this->title (), 0, 255),
-			'author' => substr($this->author (), 0, 255),
-			'content' => substr($this->content (), 0, 65535),
-			'link' => substr($this->link (), 0, 65535),
+			'guid' => $this->guid (),
+			'title' => $this->title (),
+			'author' => $this->author (),
+			'content' => $this->content (),
+			'link' => $this->link (),
 			'date' => $this->date (true),
 			'is_read' => $this->isRead (),
 			'is_favorite' => $this->isFavorite (),
 			'id_feed' => $this->feed (),
-			'tags' => substr($this->tags (true), 0, 65535),
+			'tags' => $this->tags (true),
 		);
 	}
 }
@@ -200,16 +200,16 @@ class EntryDAO extends Model_pdo {
 
 		$values = array (
 			$valuesTmp['id'],
-			$valuesTmp['guid'],
-			$valuesTmp['title'],
-			$valuesTmp['author'],
+			substr($valuesTmp['guid'], 0, 511),
+			substr($valuesTmp['title'], 0, 255),
+			substr($valuesTmp['author'], 0, 255),
 			base64_encode (gzdeflate (serialize ($valuesTmp['content']))),
-			$valuesTmp['link'],
+			substr($valuesTmp['link'], 0, 1023),
 			$valuesTmp['date'],
 			$valuesTmp['is_read'],
 			$valuesTmp['is_favorite'],
 			$valuesTmp['id_feed'],
-			$valuesTmp['tags'],
+			substr($valuesTmp['tags'], 0, 1023),
 		);
 
 		if ($stm && $stm->execute ($values)) {

+ 4 - 4
app/models/Feed.php

@@ -309,11 +309,11 @@ class FeedDAO extends Model_pdo {
 
 		$values = array (
 			$valuesTmp['id'],
-			$valuesTmp['url'],
+			substr($valuesTmp['url'], 0, 511),
 			$valuesTmp['category'],
-			$valuesTmp['name'],
-			$valuesTmp['website'],
-			$valuesTmp['description'],
+			substr($valuesTmp['name'], 0, 255),
+			substr($valuesTmp['website'], 0, 255),
+			substr($valuesTmp['description'], 0, 1023),
 			$valuesTmp['lastUpdate'],
 			base64_encode ($valuesTmp['httpAuth']),
 		);

+ 13 - 13
public/install.php

@@ -11,7 +11,7 @@ if (isset ($_GET['step'])) {
 define ('SQL_REQ_CREATE_DB', 'CREATE DATABASE %s DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;');
 
 define ('SQL_REQ_CAT', 'CREATE TABLE IF NOT EXISTS `%scategory` (
-  `id` varchar(6) NOT NULL,
+  `id` char(6) NOT NULL,
   `name` varchar(255) NOT NULL,
   `color` varchar(7) NOT NULL,
   PRIMARY KEY (`id`),
@@ -19,16 +19,16 @@ define ('SQL_REQ_CAT', 'CREATE TABLE IF NOT EXISTS `%scategory` (
 );');
 
 define ('SQL_REQ_FEED', 'CREATE TABLE IF NOT EXISTS `%sfeed` (
-  `id` varchar(6) NOT NULL,
-  `url` text NOT NULL,
-  `category` varchar(6) DEFAULT \'000000\',
+  `id` char(6) NOT NULL,
+  `url` varchar(511) NOT NULL,
+  `category` char(6) DEFAULT \'000000\',
   `name` varchar(255) NOT NULL,
-  `website` text NOT NULL,
-  `description` text NOT NULL,
+  `website` varchar(255) NOT NULL,
+  `description` varchar(1023) NOT NULL,
   `lastUpdate` int(11) NOT NULL,
   `priority` tinyint NOT NULL DEFAULT \'10\',
-  `pathEntries` varchar(500) DEFAULT NULL,
-  `httpAuth` varchar(500) DEFAULT NULL,
+  `pathEntries` varchar(511) DEFAULT NULL,
+  `httpAuth` varchar(511) DEFAULT NULL,
   `error` boolean NOT NULL DEFAULT \'0\',
   `keep_history` boolean NOT NULL DEFAULT \'0\',
   PRIMARY KEY (`id`),
@@ -39,17 +39,17 @@ define ('SQL_REQ_FEED', 'CREATE TABLE IF NOT EXISTS `%sfeed` (
 );');
 
 define ('SQL_REQ_ENTRY', 'CREATE TABLE IF NOT EXISTS `%sentry` (
-  `id` varchar(6) NOT NULL,
-  `guid` text NOT NULL,
+  `id` char(6) NOT NULL,
+  `guid` varchar(511) NOT NULL,
   `title` varchar(255) NOT NULL,
   `author` varchar(255) NOT NULL,
   `content` text NOT NULL,
-  `link` text NOT NULL,
+  `link` varchar(1023) NOT NULL,
   `date` int(11) NOT NULL,
   `is_read` boolean NOT NULL DEFAULT \'0\',
   `is_favorite` boolean NOT NULL DEFAULT \'0\',
-  `id_feed` varchar(6) NOT NULL,
-  `tags` text NOT NULL,
+  `id_feed` char(6) NOT NULL,
+  `tags` varchar(1023) NOT NULL,
   PRIMARY KEY (`id`),
   FOREIGN KEY (`id_feed`) REFERENCES %sfeed(id) ON DELETE CASCADE ON UPDATE CASCADE,
   INDEX (`is_favorite`),