Go Back   Pligg CMS Forum > Pligg Development > Modification Tutorials

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-03-2008, 11:19 PM
netfreak's Avatar
Casual Pligger
 
Join Date: Dec 2006
Posts: 54
Thanks: 3
Thanked 10 Times in 3 Posts
Mod for Optimizing DB

Those who are using pligg sites and having huge visitors will definitely came to know that they have already got huge db size and with a huge size with page views. Page views out are not that important I guess in accordance with the speed and smoothness of site operation.

Here is the quick solution for optimizing database by deleting page views (only out included here, cause others are needed for your users)

1. Create php file called "admin_delete_pv_out.php" and place at your root directory

Code:
<?php
include_once('Smarty.class.php');
$main_smarty = new Smarty;

include('config.php');
include(mnminclude.'html1.php');
include(mnminclude.'link.php');
include(mnminclude.'user.php');
include(mnminclude.'smartyvariables.php');
			
// require user to log in
force_authentication();

// restrict access to god only
$amIgod = 0;
$amIgod = $amIgod + checklevel('god');
$main_smarty->assign('amIgod', $amIgod);

$canIhaveAccess = 0;
$canIhaveAccess = $canIhaveAccess + checklevel('god');
$canIhaveAccess = $canIhaveAccess + checklevel('admin');

if($canIhaveAccess == 0){	
	$main_smarty->assign('tpl_center', $the_template . '/admin_templates/admin_access_denied');
	$main_smarty->display($the_template . '/pligg.tpl');		
	die();
}


function delete_pvout($pvid) {

    $query="SELECT * FROM " . table_pageviews . " WHERE pv_id = '$pvid'";
    if (! $result=mysql_query($query)) {die (mysql_error());}
    else {$sql_array = mysql_fetch_object($result); }
   	}

$sql_query = "SELECT * FROM " . table_pageviews . " WHERE pv_type = 'out'";

$result_pvout = mysql_query($sql_query);
$num_rows = mysql_num_rows($result_pvout);
		while($pvout = mysql_fetch_object($result_pvout))
		{
			delete_pvout($pvout->pvid);
		}
	
# set discards total to zero
$query="UPDATE " . table_totals . " SET total = '0' WHERE name = 'out'";
if (!mysql_query($query)) {die (mysql_error());}

	
echo $num_rows. " Page View of out links has deleted";

?>
<p><a href="admin_optimize_database.php">Click here</a> to optimize database</p>
2. Create another php file called "admin_optimize_database.php" and place at your root directory

here are the code

Code:
<?php
include_once('Smarty.class.php');
$main_smarty = new Smarty;

include('config.php');
include(mnminclude.'html1.php');
include(mnminclude.'link.php');
include(mnminclude.'user.php');
include(mnminclude.'smartyvariables.php');
			
// require user to log in
force_authentication();

// restrict access to god only
$amIgod = 0;
$amIgod = $amIgod + checklevel('god');
$main_smarty->assign('amIgod', $amIgod);

$canIhaveAccess = 0;
$canIhaveAccess = $canIhaveAccess + checklevel('god');
$canIhaveAccess = $canIhaveAccess + checklevel('admin');

if($canIhaveAccess == 0){	
	$main_smarty->assign('tpl_center', $the_template . '/admin_templates/admin_access_denied');
	$main_smarty->display($the_template . '/pligg.tpl');		
	die();
}

// $message = "";

    $query = "SHOW TABLE STATUS";
    $result=mysql_query($query);
    $table_list = "";
    while ($cur_table = mysql_fetch_object($result)) {
        $table_list .= $cur_table->Name.", ";
    }

    if (!empty($table_list)) {
        $table_list = substr($table_list, 0, -2);
        $query = "OPTIMIZE TABLE ".$table_list;
        mysql_query($query);
        $message = "Database optimized, press 'back' button to back to admin home";
    }

echo $message
?>
3. Add these few lines into your "admin_main_center.tpl" where you like to show the link.
Code:
<img src="{$my_pligg_base}/templates/{$the_template}/images/manage_backup.png" align="absmiddle"/> <a href="{$my_pligg_base}/admin_delete_pv_out.php">{#PLIGG_Visual_Header_AdminPanel_41#}</a><br/>
4. Add these few lines into your "lang_english.conf"
Code:
//<SECTION>HEADER</SECTION><ADDED>0.57</ADDED>
PLIGG_Visual_Header_AdminPanel_41 = "Optimize DB"
Tested and works fine for me

Thanks and regards
__________________
Drive more traffic to your blog by submitting blog..
______________________
|| Drive more Traffic || Gadgets Watch ||
Reply With Quote
The Following 8 Users Say Thank You to netfreak For This Useful Post:
  #2 (permalink)  
Old 06-03-2008, 11:27 PM
chuckroast's Avatar
Coder/Designer
Pligg Version: 1.0
Pligg Template: ExpertVision
 
Join Date: Jun 2006
Location: PA
Posts: 2,400
Thanks: 171
Thanked 440 Times in 279 Posts
Nice work man... With your permission I'd like to move this thread to the Core Development forum...
__________________
Visit PliggPro the official Pligg Mods & Template Shop!

Reply With Quote
  #3 (permalink)  
Old 06-03-2008, 11:39 PM
netfreak's Avatar
Casual Pligger
 
Join Date: Dec 2006
Posts: 54
Thanks: 3
Thanked 10 Times in 3 Posts
Wow ! this would be great !!!
__________________
Drive more traffic to your blog by submitting blog..
______________________
|| Drive more Traffic || Gadgets Watch ||
Reply With Quote
  #4 (permalink)  
Old 06-06-2008, 07:13 PM
netwb's Avatar
Casual Pligger
Pligg Version: 9.8
Pligg Template: Yget - Convergence - GarrX
 
Join Date: Dec 2006
Location: Bruxelles
Posts: 63
Thanks: 20
Thanked 25 Times in 11 Posts
i'm problem to stats to the pageviews!
i 'm install the Mod for Optimizing DB and my stats is null:
link img: you have the solution? thanks
__________________
Bruxello.com l Europeanpainting.eu l
Reply With Quote
  #5 (permalink)  
Old 06-07-2008, 12:22 AM
davemackey's Avatar
Pligg Donor
Pligg Version: 9.9.
Pligg Template: siChunkBlue
 
Join Date: Aug 2007
Location: Langhorne, PA
Posts: 286
Thanks: 33
Thanked 18 Times in 14 Posts
Thanks. Nice job.
Reply With Quote
  #6 (permalink)  
Old 06-08-2008, 12:20 AM
netfreak's Avatar
Casual Pligger
 
Join Date: Dec 2006
Posts: 54
Thanks: 3
Thanked 10 Times in 3 Posts
"netwb" Would you please make this clear to us?

Which stats you are talking about? AWstats? or ?


This mod wouldn't harm you? except the logs created for you on all outgoing which is not that much important for you. You have another pageviews like profile and story which wont be deleted if you use that mod.

Thanks
__________________
Drive more traffic to your blog by submitting blog..
______________________
|| Drive more Traffic || Gadgets Watch ||
Reply With Quote
  #7 (permalink)  
Old 06-08-2008, 02:52 AM
magpie2419's Avatar
Casual Pligger
 
Join Date: Jun 2007
Location: Libya
Posts: 61
Thanks: 15
Thanked 3 Times in 3 Posts
Works like a dream thanks very much I'm using Ver 9.7 so it works great with that Version.
__________________
www.geordies.net
Reply With Quote
Reply

Thread Tools
Display Modes
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Search Engine Friendly URLs by vBSEO 3.2.0