OK, here's an initial patch that did INSANE performance improvements on the frontpage.
if anyone can make
Code:
select link_id from pligg_links use index (PRIMARY) where link_id>=(select floor(max(link_id)*rand()) from pligg_links) order by link_id limit 1
work at a decent speed i'm all ears, i hate double querying but this just runs like a dog compared to the 2 queries, aparently the subquery is running multiple times. i'm over trying to debug it.
Code:
ALTER TABLE `pligg_links` ADD INDEX ( `link_title_url` )
ALTER TABLE `pligg_links` ADD INDEX ( `link_status` )
ALTER TABLE `pligg_votes` ADD INDEX ( `vote_type` )
3 new indexes
Code:
Index: modules/random_story/random_story_main.php
===================================================================
--- modules/random_story/random_story_main.php (revision 1176)
+++ modules/random_story/random_story_main.php (working copy)
@@ -3,14 +3,15 @@
function random_story_getdata(){
global $view, $db, $current_user, $main_smarty;
- $cols = $db->get_col('select link_id from ' . table_links . ' where `link_status` = "published" order by link_id desc limit 200;');
- //echo count($cols);
- if($cols){
- $randstory = rand(1, count($cols));
- $randstoryurl = getmyurl("story", $cols[$randstory]);
- $main_smarty->assign('random_story_randstoryurl', $randstoryurl);
- }
+ $published = $db->get_var('select count(*) from '.table_links.' where link_status="published"' );
+
+ if ( ! $published ) {
+ return;
+ }
+ $linkid = $db->get_var('select link_id from ' . table_links . ' where `link_status` = "published" limit 1 offset '.mt_rand(0,$published));
+ $randstoryurl = getmyurl("story", $linkid);
+ $main_smarty->assign('random_story_randstoryurl', $randstoryurl);
}
-?>
\ No newline at end of file
+?>
Index: libs/search.php
===================================================================
--- libs/search.php (revision 1176)
+++ libs/search.php (working copy)
@@ -115,11 +115,11 @@
if($this->searchTerm == ""){
// like when on the index or upcoming pages.
- $this->sql = "SELECT DISTINCT link_id $from_where $search_clause $this->orderBy LIMIT $this->offset,$this->pagesize";
+ $this->sql = "SELECT link_id $from_where $search_clause $this->orderBy LIMIT $this->offset,$this->pagesize";
}else{
$this->sql = "SELECT link_id, link_date, link_published_date $from_where $search_clause ";
}
- $this->countsql = "SELECT count(*) $from_where $search_clause $this->orderBy";
+ $this->countsql = "SELECT count(*) $from_where $search_clause";
return;
}
@@ -367,4 +367,4 @@
}
}
-?>
\ No newline at end of file
+?> patch some slow code
sometimes queries went from 4+seconds to .0something so this makes an incredible difference. more hunting to go, i'm sure theres more i can pull out of pligg!