]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Store foreign ID for synch info, not user ID
authorEvan Prodromou <evan@status.net>
Tue, 7 Sep 2010 14:53:11 +0000 (10:53 -0400)
committerEvan Prodromou <evan@status.net>
Tue, 7 Sep 2010 14:53:11 +0000 (10:53 -0400)
plugins/TwitterBridge/TwitterBridgePlugin.php
plugins/TwitterBridge/Twitter_synch_status.php
plugins/TwitterBridge/daemons/twitterstatusfetcher.php

index d3efb074bd54e94830b6cf2b2ef0003754e82923..21a10775ddcf45cfca1f2b9892fa5ee098bdf135 100644 (file)
@@ -383,7 +383,7 @@ class TwitterBridgePlugin extends Plugin
         // home_timeline, messages (in), messages (out), ...
 
         $schema->ensureTable('twitter_synch_status',
-                             array(new ColumnDef('user_id', 'integer', null,
+                             array(new ColumnDef('foreign_id', 'bigint', null,
                                                  false, 'PRI'),
                                    new ColumnDef('timeline', 'varchar', 255,
                                                  false, 'PRI'),
index 8ac2bdc57134c51721c4d6f91ac36dc959fbefe5..1b3ad48fea473d1df68b8a4e9e63a037eed6eac3 100644 (file)
@@ -52,7 +52,7 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
 class Twitter_synch_status extends Memcached_DataObject
 {
     public $__table = 'twitter_synch_status'; // table name
-    public $user_id;                         // int(4)  primary_key not_null
+    public $foreign_id;                         // int(4)  primary_key not_null
     public $timeline;                        // varchar(255)  primary_key not_null
     public $last_id;                         // bigint not_null
     public $created;                         // datetime not_null
@@ -61,7 +61,7 @@ class Twitter_synch_status extends Memcached_DataObject
     /**
      * Get an instance by key
      *
-     * @param string $k Key to use to lookup (usually 'user_id' for this class)
+     * @param string $k Key to use to lookup (usually 'foreign_id' for this class)
      * @param mixed  $v Value to lookup
      *
      * @return User_greeting_count object found, or null for no hits
@@ -84,7 +84,7 @@ class Twitter_synch_status extends Memcached_DataObject
 
     function table()
     {
-        return array('user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
+        return array('foreign_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
                      'timeline' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
                      'last_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
                      'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
@@ -122,7 +122,7 @@ class Twitter_synch_status extends Memcached_DataObject
 
     function keyTypes()
     {
-        return array('user_id' => 'K',
+        return array('foreign_id' => 'K',
                      'timeline' => 'K');
     }
 
@@ -142,9 +142,9 @@ class Twitter_synch_status extends Memcached_DataObject
         return array(false, false, false);
     }
 
-    static function getLastId($user_id, $timeline)
+    static function getLastId($foreign_id, $timeline)
     {
-        $tss = self::staticGet(array('user_id' => $user_id,
+        $tss = self::staticGet(array('foreign_id' => $foreign_id,
                                      'timeline' => $timeline));
 
         if (empty($tss)) {
@@ -154,20 +154,20 @@ class Twitter_synch_status extends Memcached_DataObject
         }
     }
 
-    static function setLastId($user_id, $timeline, $last_id)
+    static function setLastId($foreign_id, $timeline, $last_id)
     {
-        $tss = self::staticGet(array('user_id' => $user_id,
+        $tss = self::staticGet(array('foreign_id' => $foreign_id,
                                      'timeline' => $timeline));
 
         if (empty($tss)) {
 
             $tss = new Twitter_synch_status();
 
-            $tss->user_id  = $user_id;
-            $tss->timeline = $timeline;
-            $tss->last_id  = $last_id;
-            $tss->created  = common_sql_now();
-            $tss->modified = $tss->created;
+            $tss->foreign_id = $foreign_id;
+            $tss->timeline   = $timeline;
+            $tss->last_id    = $last_id;
+            $tss->created    = common_sql_now();
+            $tss->modified   = $tss->created;
 
             $tss->insert();
 
index c5c2752212d8d4c4d2af3b4df6f660e159abba77..79c9155035cda2ad6a09d36b21e9ae2a580b0620 100755 (executable)
@@ -182,7 +182,7 @@ class TwitterStatusFetcher extends ParallelizingDaemon
 
         $timeline = null;
 
-        $lastId = Twitter_synch_status::getLastId($flink->user_id, 'home_timeline');
+        $lastId = Twitter_synch_status::getLastId($flink->foreign_id, 'home_timeline');
 
         try {
             $timeline = $client->statusesHomeTimeline($lastId);
@@ -200,8 +200,6 @@ class TwitterStatusFetcher extends ParallelizingDaemon
 
         common_debug(LOG_INFO, $this->name() . ' - Retrieved ' . sizeof($timeline) . ' statuses from Twitter.');
 
-        $lastSeenId = null;
-
         // Reverse to preserve order
 
         foreach (array_reverse($timeline) as $status) {
@@ -232,9 +230,11 @@ class TwitterStatusFetcher extends ParallelizingDaemon
             }
         }
 
-        if (!empty($lastSeenId)) {
-            Twitter_synch_status::setLastId($flink->user_id, 'home_timeline', $lastSeenId);
-        }
+        assert(!empty($timeline)); // checked above
+
+        // First status is last in time
+
+        Twitter_synch_status::setLastId($flink->foreign_id, 'home_timeline', $timeline[0]->id);
 
         // Okay, record the time we synced with Twitter for posterity