changelog_bot (changelog_bot) wrote in changelog,
changelog_bot
changelog_bot
changelog

[ljcom] r11699: LJSV-1266: Twitter digest doesn't work f...

Committer: nnikulochkina
LJSV-1266: Twitter digest doesn't work for some users
Store last_tweet_id for using it in 'statuses/user_timeline' request.
U   trunk/bin/upgrading/update-db-local.pl
U   trunk/cgi-bin/LJ/Client/Twitter.pm
U   trunk/cgi-bin/LJ/TwitterDigest.pm
Modified: trunk/bin/upgrading/update-db-local.pl
===================================================================
--- trunk/bin/upgrading/update-db-local.pl	2012-04-12 08:44:09 UTC (rev 11698)
+++ trunk/bin/upgrading/update-db-local.pl	2012-04-12 11:21:23 UTC (rev 11699)
@@ -1525,6 +1525,7 @@
   `next_post_time` int(11) NOT NULL DEFAULT '0',
   `locked_until` int(11) NOT NULL DEFAULT '0',
   `disabled` int(11) NOT NULL DEFAULT '0',
+  `last_tweet_id` bigint unsigned NOT NULL DEFAULT 0,
   PRIMARY KEY (`userid`),
   KEY `next_post_time` (`next_post_time`)
 )
@@ -2442,6 +2443,12 @@
                   'ALTER TABLE user_wallet_history ' .
                   'MODIFY COLUMN qty BIGINT NOT NULL' );
     }
+
+    unless (column_type("twitter_digest_status", "last_tweet_id")) {
+        do_alter("twitter_digest_status",
+                 "ALTER TABLE twitter_digest_status ADD last_tweet_id BIGINT UNSIGNED NOT NULL DEFAULT 0");
+    }
+
 });
 
 1;  # true

Modified: trunk/cgi-bin/LJ/Client/Twitter.pm
===================================================================
--- trunk/cgi-bin/LJ/Client/Twitter.pm	2012-04-12 08:44:09 UTC (rev 11698)
+++ trunk/cgi-bin/LJ/Client/Twitter.pm	2012-04-12 11:21:23 UTC (rev 11699)
@@ -453,7 +453,12 @@
         # if they don't have a token, return an empty result
         return [];
     }
-
+    
+    my $params =  { 'count'       => $LJ::TWITTER_RECENT_FEED_DEPTH,
+                    'include_rts' => 1, # with retweets
+                  };
+    $params->{'since_id'} = $u->{'last_tweet_id'} if $u->{'last_tweet_id'};
+    
     my $res;
     my $retry_number = $LJ::TWITTER_API_USER_TIMELINE_RETRY || 1;
 
@@ -466,8 +471,7 @@
                 'api_method' => 'statuses/user_timeline',
                 'user' => $u,
                 'http_method' => 'GET',
-	        'params' => { 'count'       => $LJ::TWITTER_RECENT_FEED_DEPTH,
-		              'include_rts' => 1, }, # with retweets
+                'params' => $params,
                 %$opts,
 		http_code => \$http_code,
 	    );

Modified: trunk/cgi-bin/LJ/TwitterDigest.pm
===================================================================
--- trunk/cgi-bin/LJ/TwitterDigest.pm	2012-04-12 08:44:09 UTC (rev 11698)
+++ trunk/cgi-bin/LJ/TwitterDigest.pm	2012-04-12 11:21:23 UTC (rev 11699)
@@ -117,12 +117,13 @@
     # rate-limiting measure
     my $ts = LJ::TimeUtil->next_afternoon( $u->prop("timezone") || 'GMT',
                                            time + 900 );
+    my $last_tweet_id = $u->{'last_tweet_id'} || 0;
 
     my $dbh = LJ::get_db_writer(); $dbh->{'RaiseError'} = 1;
     $dbh->do(qq{
         REPLACE INTO twitter_digest_status
-        SET userid=?, next_post_time=?
-    }, undef, $u->id, $ts);
+        SET userid=?, next_post_time=?, last_tweet_id=?
+    }, undef, $u->id, $ts, $last_tweet_id);
 }
 
 sub turn_off_for_user {
@@ -175,8 +176,8 @@
     # other processes for a long time
     my $tx = LJ::Transaction->new($dbh);
 
-    my ($userid) = $dbh->selectrow_array(qq{
-        SELECT userid
+    my ($userid, $last_tweet_id) = $dbh->selectrow_array(qq{
+        SELECT userid, last_tweet_id
         FROM twitter_digest_status
         WHERE disabled       = 0
           AND next_post_time < UNIX_TIMESTAMP()
@@ -202,7 +203,11 @@
 
     $tx->commit;
 
-    return LJ::load_userid($userid);
+    my $u = LJ::load_userid($userid);
+    
+    $u->{'last_tweet_id'} = $last_tweet_id;
+
+    return $u;
 }
 
 my @weekdays_ml =
@@ -267,6 +272,8 @@
         return;
     }
     
+    $u->{'last_tweet_id'} = $tweets_filtered[-1]->id;
+
     my @tweets_display;
     foreach my $tw (@tweets_filtered) {
         my $dt = DateTime->from_epoch( 

Tags: changelog_bot, ljcom, nnikulochkina, pl, 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