vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Last Viewed Date (https://vborg.vbsupport.ru/showthread.php?t=40814)

amykhar 07-08-2002 10:19 AM

Last Viewed Date
 
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:
PHP Code:

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:
PHP Code:

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?

Admin 07-08-2002 11:55 AM

What about it?

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

Quote:

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:
PHP Code:

doformheader("thread","pruneuser"); 

Paste before:

PHP Code:

  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:

PHP Code:

// ###################### Start Prune by date ####################### 

Paste before:

PHP Code:

// ###################### 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


All times are GMT. The time now is 12:22 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.01261 seconds
  • Memory Usage 1,788KB
  • 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
  • (6)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)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