amykhar
07-08-2002, 10:19 AM
How much of an extra server hit would it be to mark a thread with a last viewed date when somebody reads it?
I would love to be able to maintain this information, and then prune based on removing threads that have not been viewed in xx number of days.
Amy
Admin
07-08-2002, 11:39 AM
You can add this information to the query that is already there, that updates the thread views.
Add a lastview field to the thread table, set it up like dateline field, and then in showthread.php replace this:
if ($noshutdownfunc) {
$DB_site->query("UPDATE thread SET views=views+1 WHERE threadid='$threadid'");
} else {
$shutdownqueries[]="UPDATE LOW_PRIORITY thread SET views=views+1 WHERE threadid='$threadid'";
}
With this:
if ($noshutdownfunc) {
$DB_site->query("UPDATE thread SET views=views+1, lastview=".time()." WHERE threadid='$threadid'");
} else {
$shutdownqueries[]="UPDATE LOW_PRIORITY thread SET views=views+1, lastview=".time()." WHERE threadid='$threadid'";
}
Birdie501
07-08-2002, 11:47 AM
and what about the server?
amykhar
07-08-2002, 12:33 PM
Thank you, Chen. :)
This means I just need to hack the prune routines a bit, and I should be good to go.
Amy
Birdie501
07-08-2002, 12:51 PM
Originally posted by FireFly
What about it?
Forget it :-)
amykhar
07-08-2002, 02:13 PM
Here is the rest of what I conceived. I am not supporting this as a released hack because I am not set up to test it thorougly. Use at YOUR OWN RISK.
Find:
doformheader("thread","pruneuser");
Paste before:
doformheader("thread","pruneviewed");
maketableheader("Prune by Date Last Viewed");
makeinputcode("Delete threads with last viewed before x days:<BR>(intensive if deleting a lot of threads)","daysdelete","0");
//makeforumchoosercode("Forum","forumid",-1,"All forums");
makeforumchooser("forumid",-1,-1,"","----- all -----","Forum:");
makeyesnocode("Include sub forums","subforums");
doformfooter("Prune");
Find:
// ###################### Start Prune by date #######################
Paste before:
// ###################### Start Prune by last viewed #######################
if ($action=="pruneviewed") {
if ($daysdelete=="") {
echo "<p>Please enter an age of last view to delete</p>";
exit;
}
if ($confirm!=1) {
if ($forumid==-1) {
$forumtitle="all forums";
} else {
$forum=$DB_site->query_first("SELECT title FROM forum WHERE forumid=$forumid");
$forumtitle="the \"$forum[title]\" forum";
if ($subforums) {
$forumtitle.=" and sub forums";
}
}
doformheader("thread","pruneviewed");
maketableheader("Prune All Threads Automatically");
makehiddencode("forumid", "$forumid");
makehiddencode("daysdelete", "$daysdelete");
makehiddencode("subforums", "$subforums");
makehiddencode("confirm", "1");
doformfooter("Click Here to Prune All Threads Automatically","",2);
doformheader("thread","prunedatevie");
maketableheader("Prune Threads Selectively");
makehiddencode("forumid", "$forumid");
makehiddencode("daysdelete", "$daysdelete");
makehiddencode("subforums", "$subforums");
doformfooter("Click Here to Prune Threads Selectively","",2);
//<a
href=\"thread.php?s=$session[sessionhash]&action=prunedatesel&forumid=$forumid&daysdelete=$daysdelete&subforums=$subforums\"><b>here</b></a>
to select those to delete.</p>";
exit;
}
if ($forumid!=-1) {
if ($subforums) {
$forumcheck="(thread.forumid=$forumid OR INSTR(parentlist,',$forumid,')>0) AND ";
} else {
$forumcheck="thread.forumid=$forumid AND ";
}
}
$datecut=time()-($daysdelete*86400);
$threads=$DB_site->query("SELECT threadid FROM thread LEFT JOIN forum USING (forumid) WHERE $forumcheck thread.lastview<=$datecut AND
thread.sticky=0");
while ($thread=$DB_site->fetch_array($threads)) {
deletethread($thread[threadid],0);
}
echo "<p>Posts deleted successfully! It is recommended that you <a href=\"misc.php?s=$session[sessionhash]\">update counters</a> now.</p>";
}
// ###################### Start Prune by date selector #######################
if ($action=="prunedatevie") {
doformheader("thread","dopruneviewed");
if ($forumid!=-1) {
if ($subforums) {
$forumcheck="(thread.forumid=$forumid OR INSTR(parentlist,',$forumid,')>0) AND ";
} else {
$forumcheck="thread.forumid=$forumid AND ";
}
}
echo "<tr class='tblhead'><td><font size='1'><b><span class='tblhead'>Thread Title</span></b></font></td><td><font size='1'><b><span
class='tblhead'>Delete?</span></b></font></td></tr>\n";
$datecut=time()-($daysdelete*86400);
$threads=$DB_site->query("SELECT threadid,thread.title,thread.replycount FROM thread LEFT JOIN forum USING (forumid) WHERE $forumcheck
thread.lastview<=$datecut ORDER BY thread.lastpost DESC");
while ($thread=$DB_site->fetch_array($threads)) {
makeyesnocode("<a href=\"../showthread.php?s=$session[sessionhash]&threadid=$thread[threadid]\"
target=_blank>$thread[title]($thread[replycount])</a>","delete[$thread[threadid]]",0);
}
doformfooter("Submit - only click here if you are ABSOLUTELY certain");
}
// ###################### Start Prune by date selected #######################
if ($HTTP_POST_VARS['action']=="dopruneviewed") {
echo "<p>Deleting...</p>";
while (list($key,$val)=each($delete)) {
if ($val==1) {
deletethread($key,0);
}
}
echo "<p>Threads deleted successfully! It is recommended that you <a href=\"misc.php?s=$session[sessionhash]\">update counters</a>
now.</p>";
}
That's it. It seems to work on my board, but I have only pruned selectively and tested minimally. I will be very cautious using this for a while until it is well proven.
Amy
amykhar
07-08-2002, 02:17 PM
One other thing. I am going to set all my lastview amounts to yesterday's date with a single one-time query in phpmyadmin and then start counting from yesterday for prune purposes.
Amy
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.