From febecb5992b042d3de20e4f30a537b61a4800031 Mon Sep 17 00:00:00 2001 From: 3dB <3db@3decibels.net> Date: Wed, 5 Aug 2009 18:23:10 -0400 Subject: Reworked double post checking to use existing code -- Removed dbPostCheckDouble -- Added more filters to dbPostGet to serve similar purpose --- lib/VNDB/DB/Discussions.pm | 24 +++--------------------- lib/VNDB/Handler/Discussions.pm | 3 ++- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/lib/VNDB/DB/Discussions.pm b/lib/VNDB/DB/Discussions.pm index eed1b2f9..6e09e0ad 100644 --- a/lib/VNDB/DB/Discussions.pm +++ b/lib/VNDB/DB/Discussions.pm @@ -153,7 +153,7 @@ sub dbThreadCount { } -# Options: tid, num, what, order, uid, hide, page, results +# Options: tid, num, what, order, uid, date >, hide, page, results # what: user thread sub dbPostGet { my($self, %o) = @_; @@ -169,6 +169,8 @@ sub dbPostGet { 'tp.num = ?' => $o{num} ) : (), $o{uid} ? ( 'tp.uid = ?' => $o{uid} ) : (), + $o{date} ? ( + 'tp.date > ?' => $o{date} ) : (), $o{hide} ? ( 'tp.hidden = FALSE' => 1 ) : (), $o{hide} && $o{what} =~ /thread/ ? ( @@ -241,25 +243,5 @@ sub dbPostAdd { } -# Checks if a user has recently made a post in a particular thread -# If tid is omitted or equal to zero, check if user has made a recent post at all -# uid, tid (optional) -sub dbPostCheckDouble { - my($self, @o) = @_; - - my $time = time - 30; # 30 Seconds - my $r; - if (defined $o[1] && $o[1] ne 0) { - $r = $self->dbRow('SELECT COUNT(num) FROM threads_posts WHERE uid = ? AND tid = ? AND date > ? LIMIT 1', - @o, $time); - } else { - $r = $self->dbRow('SELECT COUNT(num) FROM threads_posts WHERE uid = ? AND date > ? LIMIT 1', - $o[0], $time); - } - - return $r->{count}||0; -} - - 1; diff --git a/lib/VNDB/Handler/Discussions.pm b/lib/VNDB/Handler/Discussions.pm index dce8dcde..ae0961d8 100644 --- a/lib/VNDB/Handler/Discussions.pm +++ b/lib/VNDB/Handler/Discussions.pm @@ -167,7 +167,8 @@ sub edit { ); # check for double-posting - push @{$frm->{_err}}, 'doublepost' if $self->dbPostCheckDouble($self->{_auth}{id}, $tid); + push @{$frm->{_err}}, 'doublepost' if $self->dbPostGet( + uid => $self->authInfo->{id}, tid => $tid || '', date => time - 30, results=> 1)->[0]->{num}; # parse and validate the boards my @boards; -- cgit v1.2.3