Gossamer Forum
Quote Reply
Meaningful Hits Mod In reply to
OK, here is my first attempt. It's a code hack, not a plugin. Please be critical -- I do not claim to be a programmer, so I have no professional feelings that might be injured.

After backing up your database:

Add a new INT column to your Links table named 'OldHits'.

In .../admin/nph-build.cgi, insert the line in red below ...
Code:
sub main {
# -------------------------------------------------------------------
# Determine what we should build.
#
$USE_HTML = defined $ENV{REQUEST_METHOD} ? 1 : 0;
if ($USE_HTML) {
my $do = $IN->param('do') || '';
CASE: {
($do eq 'changed') and build_changed(), last CASE;
($do eq 'staggered') and build_staggered(), last CASE;
($do eq 'repair') and build_repair(), last CASE;
build_all(); # default
}
}
else {
my $arg = $ARGV[0] || '';
CASE: {
($arg eq '--all') and build_all(), last CASE;
($arg eq '--changed') and build_changed(), last CASE;
($arg eq '--repair') and build_repair(), last CASE;
($arg eq '--flags') and build_flags(), last CASE;

($arg eq '--mhits') and build_meaningful_hits(), last CASE;

usage(); # default
}
}
}


In .../admin/nph-build.cgi, add these two functions ...
Code:
sub build_meaningful_hits {
# ------------------------------------------------------------------
# Reset meaningful hits
#
_header("Resetting meaningful hits.", "Links SQL will now make your Hits meaningful.");
_build_meaningful_hits();
_build_cool_flags();
_footer();
}

sub _build_meaningful_hits {
# ------------------------------------------------------------------
# Resets meaningful hits
#
_time_start();
print "Resetting meaningful hits ... \n";
my $ret = Links::Build::build ('reset_meaningful_hits', shift || {});
print "Done (", _time_display(), " s)\n\n";
return $ret;
}


In .../admin/Links/Build.pm, add these two functions ...
Code:
$SUBS{build_reset_meaningful_hits} = <<'END_OF_SUB';
sub build_reset_meaningful_hits {
# ------------------------------------------------------------------
# Reset meaningful hits
#
my ($link_db, $sth, $id, $hits, $oldhits, $diff);

$link_db = $DB->table('Links');
$sth = $link_db->select ( ['ID', 'Hits', 'OldHits'] );
while ( ( $id, $hits, $oldhits) = $sth->fetchrow_array) {
$diff = $hits - $oldhits;
## Play safe ...
if ($diff < 0) {
$diff = 0;
}
$link_db->update (
{OldHits => $diff, Hits => $diff}, {ID => $id}, {GT_SQL_SKIP_CHECK => 1}
);
}
}
END_OF_SUB


Now you can run it as a cron job at intervals which make sense to your project ...
Code:
.../admin/nph-build.cgi --mhits

It works for us.

Last edited by:

YoYoYoYo: Aug 30, 2002, 8:34 AM
Subject Author Views Date
Thread [idea] Plugin or Mod: Reset_Hit_Count YoYoYoYo 3683 Aug 29, 2002, 1:23 AM
Post Re: [YoYoYoYo] [idea] Plugin or Mod: Reset_Hit_Count
Andy 3658 Aug 29, 2002, 1:26 AM
Thread Re: [YoYoYoYo] [idea] Plugin or Mod: Reset_Hit_Count
Teambldr 3626 Aug 29, 2002, 7:07 AM
Thread Re: [Teambldr] [idea] Plugin or Mod: Reset_Hit_Count
YoYoYoYo 3607 Aug 30, 2002, 1:45 AM
Thread Re: [YoYoYoYo] [idea] Plugin or Mod: Reset_Hit_Count
Paul 3586 Aug 30, 2002, 2:20 AM
Post Re: [Paul] [idea] Plugin or Mod: Reset_Hit_Count
YoYoYoYo 3595 Aug 30, 2002, 4:07 AM
Post Meaningful Hits Mod
YoYoYoYo 3559 Aug 30, 2002, 8:19 AM