add ad management system
improved performance of cs threads by about 500%
This commit is contained in:
parent
c8956ac0c5
commit
d26f1bdd8c
11 changed files with 740 additions and 74 deletions
|
|
@ -46,7 +46,8 @@ sub addRevision {
|
|||
if ($self->get("storageId")) {
|
||||
my $newStorage = WebGUI::Storage->get($self->session,$self->get("storageId"))->copy;
|
||||
$newSelf->update({storageId=>$newStorage->getId});
|
||||
}
|
||||
}
|
||||
$self->getThread->unmarkRead;
|
||||
return $newSelf;
|
||||
}
|
||||
|
||||
|
|
@ -412,7 +413,6 @@ sub getTemplateVars {
|
|||
$var{'rate.url.4'} = $self->getRateUrl(4);
|
||||
$var{'rate.url.5'} = $self->getRateUrl(5);
|
||||
$var{'hasRated'} = $self->hasRated;
|
||||
$var{'isMarkedRead'} = $self->isMarkedRead;
|
||||
my $gotImage;
|
||||
my $gotAttachment;
|
||||
@{$var{'attachment_loop'}} = ();
|
||||
|
|
@ -502,9 +502,12 @@ Returns a boolean indicating whether this user has already rated this post.
|
|||
sub hasRated {
|
||||
my $self = shift;
|
||||
return 1 if $self->isPoster;
|
||||
my ($flag) = $self->session->db->quickArray("select count(*) from Post_rating where assetId="
|
||||
.$self->session->db->quote($self->getId)." and ((userId=".$self->session->db->quote($self->session->user->userId)." and userId<>'1') or (userId='1' and
|
||||
ipAddress=".$self->session->db->quote($self->session->env->get("REMOTE_ADDR"))."))");
|
||||
my $flag = 0;
|
||||
if ($self->session->user->userId eq "1") {
|
||||
($flag) = $self->session->db->quickArray("select count(*) from Post_rating where assetId=? and ipAddress=?",[$self->getId, $self->session->env->get("REMOTE_ADDR")]);
|
||||
} else {
|
||||
($flag) = $self->session->db->quickArray("select count(*) from Post_rating where assetId=? and userId=?",[$self->getId, $self->session->user->userId]);
|
||||
}
|
||||
return $flag;
|
||||
}
|
||||
|
||||
|
|
@ -547,21 +550,6 @@ sub incrementViews {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 isMarkedRead ( )
|
||||
|
||||
Returns a boolean indicating whether this post is marked read for the user.
|
||||
|
||||
=cut
|
||||
|
||||
sub isMarkedRead {
|
||||
my $self = shift;
|
||||
return 1 if $self->isPoster;
|
||||
my ($isRead) = $self->session->db->quickArray("select count(*) from Post_read where userId=".$self->session->db->quote($self->session->user->userId)." and postId=".$self->session->db->quote($self->getId));
|
||||
return $isRead;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 isPoster ( )
|
||||
|
||||
Returns a boolean that is true if the current user created this post and is not a visitor.
|
||||
|
|
@ -588,22 +576,6 @@ sub isReply {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 markRead ( )
|
||||
|
||||
Marks this post read for this user.
|
||||
|
||||
=cut
|
||||
|
||||
sub markRead {
|
||||
my $self = shift;
|
||||
unless ($self->isMarkedRead) {
|
||||
$self->session->db->write("insert into Post_read (userId, postId, threadId, readDate) values (".$self->session->db->quote($self->session->user->userId).",
|
||||
".$self->session->db->quote($self->getId).", ".$self->session->db->quote($self->get("threadId")).", ".$self->session->datetime->time().")");
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 notifySubscribers ( )
|
||||
|
|
@ -719,8 +691,6 @@ sub purge {
|
|||
$storage->delete if defined $storage;
|
||||
}
|
||||
$sth->finish;
|
||||
$self->session->db->write("delete from Post_rating where assetId=".$self->session->db->quote($self->getId));
|
||||
$self->session->db->write("delete from Post_read where postId=".$self->session->db->quote($self->getId));
|
||||
return $self->SUPER::purge;
|
||||
}
|
||||
|
||||
|
|
@ -838,19 +808,6 @@ sub trash {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 unmarkRead ( )
|
||||
|
||||
Negates the markRead method.
|
||||
|
||||
=cut
|
||||
|
||||
sub unmarkRead {
|
||||
my $self = shift;
|
||||
$self->session->db->write("delete from forumRead where userId=".$self->session->db->quote($self->session->user->userId)." and postId=".$self->session->db->quote($self->getId));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 update
|
||||
|
||||
We overload the update method from WebGUI::Asset in order to handle file system privileges.
|
||||
|
|
@ -873,7 +830,6 @@ sub update {
|
|||
#-------------------------------------------------------------------
|
||||
sub view {
|
||||
my $self = shift;
|
||||
$self->markRead;
|
||||
$self->incrementViews;
|
||||
return $self->getThread->view;
|
||||
}
|
||||
|
|
@ -1120,7 +1076,6 @@ sub www_showConfirmation {
|
|||
#-------------------------------------------------------------------
|
||||
sub www_view {
|
||||
my $self = shift;
|
||||
$self->markRead;
|
||||
$self->incrementViews;
|
||||
return $self->getThread->www_view;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -434,7 +434,7 @@ Returns a boolean indicating whether this thread is marked read for the user.
|
|||
sub isMarkedRead {
|
||||
my $self = shift;
|
||||
return 1 if $self->isPoster;
|
||||
my ($isRead) = $self->session->db->quickArray("select count(*) from Post_read where userId=".$self->session->db->quote($self->session->user->userId)." and threadId=".$self->session->db->quote($self->getId)." and postId=".$self->session->db->quote($self->get("lastPostId")));
|
||||
my ($isRead) = $self->session->db->quickArray("select count(*) from Thread_read where threadId=? and userId=?",[$self->getId,$self->session->user->userId]);
|
||||
return $isRead;
|
||||
}
|
||||
|
||||
|
|
@ -479,6 +479,19 @@ sub lock {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 markRead ( )
|
||||
|
||||
Marks this post read for this user.
|
||||
|
||||
=cut
|
||||
|
||||
sub markRead {
|
||||
my $self = shift;
|
||||
$self->session->db->write("replace into Thread_read (threadId, userId) values (?,?)",[$self->getId,$self->session->user->userId]);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 prepareView ( )
|
||||
|
|
@ -512,6 +525,12 @@ sub processPropertiesFromFormPost {
|
|||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub purge {
|
||||
my $self = shift;
|
||||
$self->session->db->write("delete from Thread_read where postId=?",[$self->getId]);
|
||||
return $self->SUPER::purge;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -673,6 +692,19 @@ sub unlock {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 unmarkRead ( )
|
||||
|
||||
unmarks this post read for all users.
|
||||
|
||||
=cut
|
||||
|
||||
sub unmarkRead {
|
||||
my $self = shift;
|
||||
$self->session->db->write("delete from Thread_read where threadId=?",[$self->getId]);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 unstick ( )
|
||||
|
||||
Negates the stick method.
|
||||
|
|
|
|||
|
|
@ -47,9 +47,10 @@ sub appendPostListTemplateVars {
|
|||
push(@rating_loop,{'rating_loop.count'=>$i});
|
||||
}
|
||||
my %lastReply;
|
||||
my $hasRead = 0;
|
||||
if ($post->get("className") =~ /Thread/) {
|
||||
my $lastPost = $post->getLastPost();
|
||||
if ($self->get("displayLastReply")) {
|
||||
my $lastPost = $post->getLastPost();
|
||||
%lastReply = (
|
||||
"lastReply.url"=>$lastPost->getUrl.'#'.$lastPost->getId,
|
||||
"lastReply.title"=>$lastPost->get("title"),
|
||||
|
|
@ -60,6 +61,7 @@ sub appendPostListTemplateVars {
|
|||
"lastReply.timeSubmitted.human"=>$self->session->datetime->epochToHuman($lastPost->get("dateSubmitted"),"%Z")
|
||||
);
|
||||
}
|
||||
$hasRead = $post->isMarkedRead;
|
||||
}
|
||||
my $url;
|
||||
if ($post->get("status") eq "pending") {
|
||||
|
|
@ -88,6 +90,7 @@ sub appendPostListTemplateVars {
|
|||
"isThird"=>(($i+1)%3==0),
|
||||
"isFourth"=>(($i+1)%4==0),
|
||||
"isFifth"=>(($i+1)%5==0),
|
||||
"user.hasRead" => $hasRead,
|
||||
"user.isPoster"=>$post->isPoster,
|
||||
"avatar.url"=>$post->getAvatarUrl,
|
||||
%lastReply
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue