vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   cleanup.php / cleanup2.php (https://vborg.vbsupport.ru/showthread.php?t=138548)

kofoid 02-05-2007 07:28 PM

cleanup.php / cleanup2.php
 
Hi - I am running 3.5.4 and these two cron jobs are REALLY slowing down my forums for up to 2 minutes at a time. Is there any reason I can't change these to run once a day? Is there anything I can comment out? Here's what I have in them:

cleanup.php:
PHP Code:

<?php
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 3.5.4 - Licence Number XXXXXXXXXX
|| # ---------------------------------------------------------------- # ||
|| # Copyright ?2000-2006 Jelsoft Enterprises Ltd. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/

// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
if (!
is_object($vbulletin->db))
{
    exit;
}

// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################

$vbulletin->db->query_write("
    DELETE FROM " 
TABLE_PREFIX "session
    WHERE lastactivity < " 
intval(TIMENOW $vbulletin->options['cookietimeout']) . "
    ### Delete stale sessions ###
"
);

$vbulletin->db->query_write("
    DELETE FROM " 
TABLE_PREFIX "cpsession
    WHERE dateline < " 
intval(TIMENOW 3600) . "
    ### Delete stale cpsessions ###
"
);

//searches expire after one hour
$vbulletin->db->query_write("
    DELETE FROM " 
TABLE_PREFIX "search
    WHERE dateline < " 
. (TIMENOW 3600) . "
    ### Remove stale searches ###
"
);

// expired lost passwords and email confirmations after 4 days
$vbulletin->db->query_write("
    DELETE FROM " 
TABLE_PREFIX "useractivation
    WHERE dateline < " 
. (TIMENOW 345600) . " AND
    (type = 1 OR (type = 0 and usergroupid = 2))
    ### Delete stale password and email confirmation requests ###
"
);

// old forum/thread read marking data
$vbulletin->db->query_write("
    DELETE FROM " 
TABLE_PREFIX "threadread
    WHERE readtime < " 
. (TIMENOW - ($vbulletin->options['markinglimit'] * 3600))
);
$vbulletin->db->query_write("
    DELETE FROM " 
TABLE_PREFIX "forumread
    WHERE readtime < " 
. (TIMENOW - ($vbulletin->options['markinglimit'] * 3600))
);

//[p:cron_script_cleanup]
if ($vbulletin->options['vbpager_delete_read'])
     {
if (!
function_exists("vbpager_totalpager"))
{
function 
vbpager_totalpager($userid 0)
{
    global 
$vbulletin;

    if (
$userid 0)
     {
        
$result $vbulletin->db->query_first("SELECT count(*) AS totalpager 
                    FROM " 
TABLE_PREFIX "pagerreceipt 
                    WHERE (userid = 
$userid AND active = 1 ) 
                    OR (touserid = 
$userid AND markdeleted = 0)");
        
$totalpager    intval($result['totalpager']);
        return 
$totalpager;
     }
    return 
0;
}
}
if (!
function_exists("vbpager_totalunread"))
{
function 
vbpager_totalunread($userid 0)
{
    global 
$vbulletin;
    if (
$userid 0)
     {
        
$result $vbulletin->db->query_first("SELECT count(*) AS totalpager 
                    FROM " 
TABLE_PREFIX "pagerreceipt 
                    WHERE (touserid = 
$userid AND markdeleted = 0) 
                    AND readtime = 0"
);
        
$totalpager    intval($result['totalpager']);
    
        return 
$totalpager;
     }
}
}

if (!
function_exists("vbpager_updatedb"))
{

function 
vbpager_updatedb($uid 0)
{
    global 
$vbulletin;
    
$pagerusers $vbulletin->db->query_read("SELECT userid 
                        FROM " 
TABLE_PREFIX "user " .
                        
iif($uid 0" WHERE userid = '$uid' "' ') . 
                        ORDER BY userid"
);        
    
$i    0;
    while (
$pageruser $vbulletin->db->fetch_array($pagerusers))
     {        
         
$userid        $pageruser['userid'];
         
$sumpager    vbpager_totalpager($userid);
         
$unreadsum    vbpager_totalunread($userid);

        
$i++;
         
$vbulletin->db->query_write("UPDATE " TABLE_PREFIX "user SET 
                 pagertotal = '
$sumpager', pagerunread = '$unreadsum
                 WHERE userid = 
$userid ");
     }    
    return 
$i;
}
}


// Orphaned pagertext records are removed after one hour.
// When we delete PAGERs we only delete the pager record, leaving
// the pagertext record alone for this script to clean up


$result    $vbulletin->db->query(
        UPDATE " 
TABLE_PREFIX "pagerreceipt
        SET markdeleted =1, active = 0 WHERE readtime > 0"
);
     }

$result    $vbulletin->db->query(
        DELETE FROM " 
TABLE_PREFIX "pagerreceipt
        WHERE active = 0 AND markdeleted = 1"
);
                             
$pagertexts $vbulletin->db->query_read("
        SELECT p.pagerid FROM " 
TABLE_PREFIX "pagertext AS p 
        LEFT JOIN " 
TABLE_PREFIX "pagerreceipt AS r  
        USING (pagerid) WHERE r.pagerid is NULL"
);


if (
$vbulletin->db->num_rows($pagertexts))
{
    
$pids '0';
    while (
$pager $vbulletin->db->fetch_array($pagertexts))
    {
        
$pids .= ",$pager[pagerid]";
    }
    
$vbulletin->db->query_write("DELETE FROM " TABLE_PREFIX "pagertext WHERE pagerid IN($pids)");
}
$vbulletin->db->free_result($pagertexts);
    if (
$vbulletin->options['vbpager_delete_read'])
     {
$result vbpager_updatedb();
     }
//[/p:cron_script_cleanup]

log_cron_action('Hourly Cleanup #1 Completed'$nextitem);

/*======================================================================*\
|| ####################################################################
|| # Downloaded: 10:18, Tue Aug 15th 2006
|| # CVS: $RCSfile: cleanup.php,v $ - $Revision: 1.33 $
|| ####################################################################
\*======================================================================*/
?>


cleanup2.php:
PHP Code:

<?php
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 3.5.4 - Licence Number XXXXXXXXXXX
|| # ---------------------------------------------------------------- # ||
|| # Copyright ?2000-2006 Jelsoft Enterprises Ltd. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/

// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
if (!
is_object($vbulletin->db))
{
    exit;
}

// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################

$vbulletin->db->query_write("
    DELETE FROM " 
TABLE_PREFIX "session
    WHERE lastactivity < " 
intval(TIMENOW $vbulletin->options['cookietimeout']) . "
    ### Delete stale sessions ###
"
);

// posthashes are only valid for 5 minutes
$vbulletin->db->query_write("
    DELETE FROM " 
TABLE_PREFIX "posthash
    WHERE dateline < " 
. (TIMENOW 300)
);

// expired registration images after 1 hour
$vbulletin->db->query_write("
    DELETE FROM " 
TABLE_PREFIX "regimage
    WHERE dateline < " 
. (TIMENOW 3600)
);

// expired cached posts
$vbulletin->db->query_write("
    DELETE FROM " 
TABLE_PREFIX "post_parsed
    WHERE dateline < " 
. (TIMENOW - ($vbulletin->options['cachemaxage'] * 60 60 24))
);

// Orphaned Attachments are removed after one hour
$attachdata =& datamanager_init('Attachment'$vbulletinERRTYPE_SILENT);
$attachdata->set_condition("attachment.postid = 0 AND attachment.dateline < " . (TIMENOW 3600));
$attachdata->delete();

// Orphaned pmtext records are removed after one hour.
// When we delete PMs we only delete the pm record, leaving
// the pmtext record alone for this script to clean up
$pmtexts $vbulletin->db->query_read("
    SELECT pmtext.pmtextid
    FROM " 
TABLE_PREFIX "pmtext AS pmtext
    LEFT JOIN " 
TABLE_PREFIX "pm AS pm USING(pmtextid)
    WHERE pm.pmid IS NULL
"
);
if (
$vbulletin->db->num_rows($pmtexts))
{
    
$pmtextids '0';
    while (
$pmtext $vbulletin->db->fetch_array($pmtexts))
    {
        
$pmtextids .= ",$pmtext[pmtextid]";
    }
    
$vbulletin->db->query_write("DELETE FROM " TABLE_PREFIX "pmtext WHERE pmtextid IN($pmtextids)");
}
$vbulletin->db->free_result($pmtexts);

log_cron_action('Hourly Cleanup #2 Completed'$nextitem);

/*======================================================================*\
|| ####################################################################
|| # Downloaded: 10:18, Tue Aug 15th 2006
|| # CVS: $RCSfile: cleanup2.php,v $ - $Revision: 1.23 $
|| ####################################################################
\*======================================================================*/
?>



All times are GMT. The time now is 08:21 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02059 seconds
  • Memory Usage 1,804KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (1)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete