Browse Source

Ajout d'index pour améliorer les performances lors des jointures
correction requêtes count avec jointure non nécessaire
- test fait avec 3200 feed en BDD. par§s avoir récupéré du temps de synchro, je récupère les temps sur la navigation

cobalt74 8 years ago
parent
commit
456a1765dc
3 changed files with 16 additions and 10 deletions
  1. 4 3
      Event.class.php
  2. 3 2
      Feed.class.php
  3. 9 5
      MysqlEntity.class.php

+ 4 - 3
Event.class.php

@@ -25,7 +25,9 @@ class Event extends MysqlEntity{
 		'unread'=>'integer',
 		'favorite'=>'integer',
 		'pubdate'=>'integer',
-		'indexfeed;feed'=>'index'
+		'indexfeed;feed'=>'index',
+		'indexunread;unread'=>'index',
+		'indexfavorite;favorite'=>'index'
 	);
 
 	function __construct($guid=null,$title=null,$description=null,$content=null,$pubdate=null,$link=null,$category=null,$creator=null){
@@ -44,8 +46,7 @@ class Event extends MysqlEntity{
 
 	function getEventCountPerFolder(){
 		$events = array();
-		$results = $this->customQuery('SELECT COUNT('.MYSQL_PREFIX.$this->TABLE_NAME.'.id),'.MYSQL_PREFIX.'folder.id FROM '.MYSQL_PREFIX.$this->TABLE_NAME.' INNER JOIN '.MYSQL_PREFIX.'feed ON ('.MYSQL_PREFIX.'event.feed = '.MYSQL_PREFIX.'feed.id) INNER JOIN '.MYSQL_PREFIX.'folder ON ('.MYSQL_PREFIX.'folder.id = '.MYSQL_PREFIX.'feed.folder) WHERE '.MYSQL_PREFIX.$this->TABLE_NAME.'.unread=1 GROUP BY '.MYSQL_PREFIX.'folder.id');
-		
+		$results = $this->customQuery('SELECT COUNT('.MYSQL_PREFIX.$this->TABLE_NAME.'.id),'.MYSQL_PREFIX.'feed.folder FROM '.MYSQL_PREFIX.$this->TABLE_NAME.' INNER JOIN '.MYSQL_PREFIX.'feed ON ('.MYSQL_PREFIX.'event.feed = '.MYSQL_PREFIX.'feed.id) WHERE '.MYSQL_PREFIX.$this->TABLE_NAME.'.unread=1 GROUP BY '.MYSQL_PREFIX.'feed.folder');
 		while($item = mysql_fetch_array($results)){
 			$events[$item[1]] = $item[0];
 		}

+ 3 - 2
Feed.class.php

@@ -19,7 +19,8 @@ class Feed extends MysqlEntity{
 		'website'=>'longstring',
 		'url'=>'longstring',
 		'lastupdate'=>'string',
-		'folder'=>'integer'
+		'folder'=>'integer',
+		'indexfolder;folder'=>'index'
 	);
 
 	protected $error = '';
@@ -228,7 +229,7 @@ class Feed extends MysqlEntity{
 
 	function countUnreadEvents(){
 		$unreads = array();
-		$results = Feed::customQuery("SELECT COUNT(".MYSQL_PREFIX."event.id), ".MYSQL_PREFIX."feed.id FROM ".MYSQL_PREFIX."event INNER JOIN ".MYSQL_PREFIX."feed ON (".MYSQL_PREFIX."event.feed = ".MYSQL_PREFIX."feed.id) WHERE ".MYSQL_PREFIX."event.unread = '1' GROUP BY ".MYSQL_PREFIX."feed.id") ;
+		$results = Feed::customQuery("SELECT COUNT(".MYSQL_PREFIX."event.id), ".MYSQL_PREFIX."event.feed FROM ".MYSQL_PREFIX."event WHERE ".MYSQL_PREFIX."event.unread = 1 GROUP BY ".MYSQL_PREFIX."event.feed") ;
 		if($results!=false){
 			while($item = mysql_fetch_array($results)){
 				$unreads[$item[1]] = $item[0];

+ 9 - 5
MysqlEntity.class.php

@@ -127,11 +127,15 @@ class MysqlEntity
 		$i=false;
 		foreach($this->object_fields as $field=>$type){
 			if($i){$query .=',';}else{$i=true;}
-			if ($type=='index') {
-				$fieldTab = explode(';',$field,2);
-				$query .= $this->sgbdType($type).' `'.$fieldTab[0].'` (`'.$fieldTab[1].'`)';
-			} else {
-				$query .='`'.$field.'`  '. $this->sgbdType($type).'  NOT NULL';
+			switch($type){
+				case 'index':
+					//KEY `index_name` (`name`)
+					$fieldTab = explode(';',$field,2);
+					$query .= $this->sgbdType($type).' `'.$fieldTab[0].'` (`'.$fieldTab[1].'`)';
+				break;
+				default:
+					$query .='`'.$field.'`  '. $this->sgbdType($type).'  NOT NULL';
+				break;
 			}
 		}