From 17c3b131cea790b4f761bf8dc5e3c793b1da3464 Mon Sep 17 00:00:00 2001 From: Arslan Hassan Date: Tue, 9 Aug 2011 23:08:23 +0000 Subject: [PATCH] Added : Cached pagination system --- upload/admin_area/main.php | 2 + .../admin_area/styles/cbv2/layout/main.html | 23 +++++++++ upload/cb_install/sql/configs.sql | 3 +- upload/cb_install/sql/upgrade_2.6.sql | 5 +- upload/channels.php | 22 +++++--- upload/includes/functions.php | 50 +++++++++++++++++++ upload/videos.php | 17 +++++-- 7 files changed, 109 insertions(+), 13 deletions(-) diff --git a/upload/admin_area/main.php b/upload/admin_area/main.php index a70ca2a7..0f08ab90 100644 --- a/upload/admin_area/main.php +++ b/upload/admin_area/main.php @@ -186,6 +186,8 @@ if(isset($_POST['update'])){ 'users_items_search_page', 'users_items_group_page', 'user_max_chr', + 'use_cached_pagin', + 'cached_pagin_time', 'vid_categories', 'vid_cat_height', diff --git a/upload/admin_area/styles/cbv2/layout/main.html b/upload/admin_area/styles/cbv2/layout/main.html index e4da1a26..25769db8 100644 --- a/upload/admin_area/styles/cbv2/layout/main.html +++ b/upload/admin_area/styles/cbv2/layout/main.html @@ -788,6 +788,29 @@ $(document).ready(function(){     + + Main Settings + + + Use cached pagination + + + + Pagination chaching time + + in minutes + + +   +   + Videos Listing diff --git a/upload/cb_install/sql/configs.sql b/upload/cb_install/sql/configs.sql index f47eba99..820e1c24 100644 --- a/upload/cb_install/sql/configs.sql +++ b/upload/cb_install/sql/configs.sql @@ -244,4 +244,5 @@ INSERT INTO `{tbl_prefix}config` (`configid` ,`name` ,`value`)VALUES -- Addition for 2.6 INSERT INTO `{tbl_prefix}config` (`configid`, `name`, `value`) VALUES (NULL, 'facebook_embed', 'yes'); INSERT INTO `{tbl_prefix}config` (`configid`, `name`, `value`) VALUES (NULL, 'seo_vido_url', '1'); - +INSERT INTO `{tbl_prefix}config` (`configid`, `name`, `value`) VALUES (NULL, 'use_cached_pagin', 'yes'), +(NULL, 'cached_pagin_time', '5'); diff --git a/upload/cb_install/sql/upgrade_2.6.sql b/upload/cb_install/sql/upgrade_2.6.sql index ac4d695a..6f969842 100644 --- a/upload/cb_install/sql/upgrade_2.6.sql +++ b/upload/cb_install/sql/upgrade_2.6.sql @@ -1,4 +1,7 @@ ALTER TABLE `{tbl_prefix}video` CHANGE `category` `category` VARCHAR( 200 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0'; ALTER TABLE `{tbl_prefix}collections` CHANGE `category` `category` VARCHAR( 200 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ; INSERT INTO `{tbl_prefix}config` (`configid`, `name`, `value`) VALUES (NULL, 'facebook_embed', 'yes'); -INSERT INTO `{tbl_prefix}config` (`configid`, `name`, `value`) VALUES (NULL, 'seo_vido_url', '0'); \ No newline at end of file +INSERT INTO `{tbl_prefix}config` (`configid`, `name`, `value`) VALUES (NULL, 'seo_vido_url', '0'); + +INSERT INTO `{tbl_prefix}config` (`configid`, `name`, `value`) VALUES (NULL, 'use_cached_pagin', 'yes'), +(NULL, 'cached_pagin_time', '5'); diff --git a/upload/channels.php b/upload/channels.php index 3d4f1842..7fdf875f 100644 --- a/upload/channels.php +++ b/upload/channels.php @@ -50,19 +50,27 @@ switch($sort) //Getting User List $page = mysql_clean($_GET['page']); $get_limit = create_query_limit($page,CLISTPP); -$ulist = $u_cond; +$count_query = $ulist = $u_cond; $ulist['limit'] = $get_limit; $users = get_users($ulist); Assign('users', $users); -//Collecting Data for Pagination -$ucount = $u_cond; -$ucount['count_only'] = true; -$total_rows = get_users($ucount); -$total_pages = count_pages($total_rows,CLISTPP); + +$counter = get_counter('channel',$count_query); + +if(!$counter) +{ + //Collecting Data for Pagination + $ucount = $u_cond; + $ucount['count_only'] = true; + $total_rows = get_users($ucount); + $total_pages = count_pages($total_rows,CLISTPP); + $counter = $total_pages; + update_counter('channel',$count_query,$counter); +} //Pagination -$pages->paginate($total_pages,$page); +$pages->paginate($counter,$page); subtitle(lang('channels')); template_files('channels.html'); diff --git a/upload/includes/functions.php b/upload/includes/functions.php index fc2cc57e..b9a491b9 100644 --- a/upload/includes/functions.php +++ b/upload/includes/functions.php @@ -5807,4 +5807,54 @@ return false; } } + + + /** + * function used to get counts from + * cb_counter table + */ + function get_counter($section,$query) + { + if(!config('use_cached_pagin')) + return false; + + global $db; + + $timeRefresh = config('cached_pagin_time'); + $timeRefresh = $timeRefresh*60; + + $validTime = time()-$timeRefresh; + + unset($query['order']); + $je_query = json_encode($query); + $query_md5 = md5($je_query); + $select = $db->select(tbl('counters'),"*","section='$section' AND query_md5='$query_md5' + AND '$validTime' < date_added"); + if($db->num_rows>0) + { + return $select[0]['counts']; + }else + return false; + } + + /** + * function used to insert or update counter + */ + function update_counter($section,$query,$counter) + { + global $db; + unset($query['order']); + $je_query = json_encode($query); + $query_md5 = md5($je_query); + $count = $db->count(tbl('counters'),"*","section='$section' AND query_md5='$query_md5'"); + if($count) + { + $db->update(tbl('counters'),array('counts','date_added'),array($counter,strtotime(now())), + "section='$section' AND query_md5='$query_md5'"); + }else + { + $db->insert(tbl('counters'),array('section','query','query_md5','counts','date_added'), + array($section,'|no_mc|'.$je_query,$query_md5,$counter,strtotime(now()))); + } + } ?> \ No newline at end of file diff --git a/upload/videos.php b/upload/videos.php index d3a14fa3..9192c757 100644 --- a/upload/videos.php +++ b/upload/videos.php @@ -74,6 +74,7 @@ switch($sort) $page = mysql_clean($_GET['page']); $get_limit = create_query_limit($page,VLISTPP); $vlist = $vid_cond; +$count_query = $vid_cond; $vlist['limit'] = $get_limit; $videos = get_videos($vlist); Assign('videos', $videos); @@ -81,11 +82,19 @@ Assign('videos', $videos); //Collecting Data for Pagination $vcount = $vid_cond; -$vcount['count_only'] = true; -$total_rows = get_videos($vcount); -$total_pages = count_pages($total_rows,VLISTPP); + +$counter = get_counter('video',$count_query); + +if(!$counter) +{ + $vcount['count_only'] = true; + $total_rows = get_videos($vcount); + $total_pages = count_pages($total_rows,VLISTPP); + $counter = $total_pages; + update_counter('video',$count_query,$counter); +} //Pagination -$pages->paginate($total_pages,$page); +$pages->paginate($counter,$page); subtitle(lang('videos')); //Displaying The Template