журнал (shhh) wrote in changelog,
журнал
shhh
changelog

[livejournal] r22592: LJSUP-13108: Paid repost button

Committer: nnikulochkina
LJSUP-13108: Paid repost button
U   trunk/cgi-bin/LJ/Entry/Repost.pm
Modified: trunk/cgi-bin/LJ/Entry/Repost.pm
===================================================================
--- trunk/cgi-bin/LJ/Entry/Repost.pm	2012-08-07 15:23:42 UTC (rev 22591)
+++ trunk/cgi-bin/LJ/Entry/Repost.pm	2012-08-08 06:26:10 UTC (rev 22592)
@@ -242,6 +242,39 @@
         return;
     }
 
+    my $mark = $entry_obj->journalid . ":" . $entry_obj->jitemid;
+    $post_obj->convert_to_repost($mark);
+    $post_obj->set_prop( 'repost' => 'e' );
+
+    my $lock_name = join ':', ('repost', 
+                               $entry_obj->journalid, 
+                               $entry_obj->jitemid, 
+                               $u->id);
+                                         
+    my $get_lock = sub {
+        LJ::get_lock( LJ::get_db_writer(), 'global', $lock_name );
+    };
+    
+    my $release_lock = sub {
+        LJ::release_lock( LJ::get_db_writer(), 'global', $lock_name );
+    };
+    
+    my $fail = sub {
+        $$error = shift;
+        $release_lock->();
+        LJ::delete_entry($u->id, $post_obj->jitemid, undef, $post_obj->anum);
+        return;
+    };
+
+    $get_lock->() or return $fail->(LJ::API::Error->get_error('unknown_error'));
+
+    my ($repost_itemid) = __get_repost( $entry_obj->journal,
+                                        $entry_obj->jitemid,
+                                        $u->userid );
+    if ($repost_itemid) {
+        return $fail->(LJ::API::Error->get_error('repost_already_exist'));
+    }
+
     my $blid = 0;
 
     if ($cost) {
@@ -257,22 +290,14 @@
                                                   qty              => $cost,
                                                   );
         unless($blid){
-            LJ::delete_entry($u->id, $post_obj->jitemid, undef, $post_obj->anum);
-            $$error = $err || LJ::API::Error->get_error('repost_blocking_error');
-            return;  
+            return $fail->($err || LJ::API::Error->get_error('repost_blocking_error'));
         }
     }
 
-    my $mark = $entry_obj->journalid . ":" . $entry_obj->jitemid;
-    $post_obj->convert_to_repost($mark);
-    $post_obj->set_prop( 'repost' => 'e' );
-
     #
     # create record
     #
     my $repost_jitemid = $post_obj->jitemid;
-    
-    my $journalid = $entry_obj->journalid;
     my $jitemid   = $entry_obj->jitemid;
 
     __create_repost_record($entry_obj->journal,
@@ -283,6 +308,8 @@
                            $blid,
                            );
 
+    $release_lock->();
+
     return $post_obj;
 }
 
@@ -599,16 +626,14 @@
     my $journalid = $entry_obj->journalid;
     my $jitemid   = $entry_obj->jitemid;
 
-    my ($repost_itemid) = __get_repost( $entry_obj->journal, 
-                                      $jitemid, 
-                                      $u->userid );
-    my $error;
-    if ($repost_itemid) {
 
+    my $memcache_key = join ':', 'reposted_item', $entry_obj->journalid, $entry_obj->jitemid, $u->id;
+    if (LJ::MemCache::get($memcache_key)) {
         return LJ::API::Error->get_error('repost_already_exist');
+    }
 
-    } 
-      
+    my $error;
+
     my $reposted_obj = __create_repost( {'u'          => $u,
                                          'entry_obj'  => $entry_obj,
                                          'timezone'   => $timezone,

Tags: livejournal, nikulochkina, nnikulochkina, 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