Alexander Nazarov (nfokz) wrote in changelog,
Alexander Nazarov
nfokz
changelog

[ljcom] r11305: LJSUP-10934: Promoted entries in the rat...

Committer: anazarov
LJSUP-10934: Promoted entries in the rating
U   trunk/cgi-bin/LJ/Pay/SelfPromo.pm
U   trunk/htdocs/shop/selfpromo.bml.text.local
Modified: trunk/cgi-bin/LJ/Pay/SelfPromo.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/SelfPromo.pm	2012-01-11 06:26:20 UTC (rev 11304)
+++ trunk/cgi-bin/LJ/Pay/SelfPromo.pm	2012-01-12 08:56:34 UTC (rev 11305)
@@ -515,6 +515,11 @@
         push @binds, $started_min;
     }
 
+    if ( my $finished_min = delete $params->{'finished_min'} ) {
+        push @where, '(finished > ?'. (delete $params->{'unfinished'}? ' OR active = 1' : ''). ')';
+        push @binds, $finished_min;
+    }
+
     if ( my $promoid = delete $params->{'promoid'} ) {
         push @where, 'promoid = ?';
         push @binds, $promoid;
@@ -525,6 +530,16 @@
         push @binds, $promoid_max;
     }
 
+    if ( my $ditemid = delete $params->{'ditemid'} ) {
+        push @where, 'ditemid = ?';
+        push @binds, $ditemid;
+    }
+
+    if ( my $posterid = delete $params->{'posterid'} ) {
+        push @where, 'posterid = ?';
+        push @binds, $posterid;
+    }
+
     if ( delete $params->{'require_active'} ) {
         push @where, 'active = 1';
     }
@@ -551,6 +566,18 @@
     return $promos;
 }
 
+sub was_promoted {
+    my ($class, $entry) = @_;
+    return undef unless UNIVERSAL::isa($entry, 'LJ::Entry');
+
+    return LJ::MemCache::get_or_set(
+        $class->was_promoted_key($entry->posterid, $entry->ditemid), sub {
+            my $res = $class->find_promos({ ditemid => $entry->ditemid, posterid => $entry->posterid });
+            return @$res? 1 : 0;
+        }, 7200
+    );
+}
+
 ### LOW LEVEL INTERFACE ###
 
 # !$promoid => currently promoted entry
@@ -622,7 +649,7 @@
         'promoterid' => $promoter? $promoter->userid : $entry->posterid,
     );
 
-    $class->clear_memcache;
+    $class->clear_memcache($entry->posterid, $entry->ditemid);
 
     $class->log(
         $promoter,
@@ -856,11 +883,13 @@
 }
 
 sub clear_memcache {
-    my ($class) = @_;
+    my ($class, $posterid, $ditemid) = @_;
     LJ::MemCache::delete( $class->memcache_key );
+    LJ::MemCache::delete( $class->was_promoted_key($posterid, $ditemid) ) if $posterid and $ditemid;
 }
 
-sub memcache_key {'self_promo_active'}
+sub memcache_key     { 'self_promo_active' }
+sub was_promoted_key { 'self_promo_ditemid_promoted:'. join ':', $_[1], $_[2] }
 
 sub raise_error {
     my ( $class, @args ) = @_;

Modified: trunk/htdocs/shop/selfpromo.bml.text.local
===================================================================
--- trunk/htdocs/shop/selfpromo.bml.text.local	2012-01-11 06:26:20 UTC (rev 11304)
+++ trunk/htdocs/shop/selfpromo.bml.text.local	2012-01-12 08:56:34 UTC (rev 11305)
@@ -17,6 +17,8 @@
 .current_price|staleness=1
 .current_price=[[price]] [[?price|LJ Token|LJ Tokens|LJ Tokens]]
 
+.entry_was_promoted=This entry was promoted in SelfPromo
+
 .error.entry_ineligible.cannot_manage=You cannot promote the entry at <a href="[[entry_url]]">[[entry_url]]</a> because you are not its author or community's owner/maintainer.
 
 .error.entry_ineligible.entry_adult_content=The entry at <a href="[[entry_url]]">[[entry_url]]</a> cannot be promoted because it is marked as containing adult content.

Tags: anazarov, ljcom, local, nfokz, pm
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments