From 656d861b3ea83ff2acdc5e0c1c7bc3da86dc7c3a Mon Sep 17 00:00:00 2001 From: Friendika Date: Sun, 29 May 2011 22:50:36 -0700 Subject: [PATCH] on rare occasions posts do not get a parent. The only thing which could cause it is if we can't find our new post. So we'll check for this and try one more time before failing. --- addon/facebook/facebook.php | 8 ++++++-- include/items.php | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/addon/facebook/facebook.php b/addon/facebook/facebook.php index b1ba6342ad..dc1aa02dd9 100644 --- a/addon/facebook/facebook.php +++ b/addon/facebook/facebook.php @@ -725,8 +725,10 @@ function fb_consume_stream($uid,$j,$wall = false) { // don't store post if we don't have a contact - if(! x($datarray,'contact-id')) + if(! x($datarray,'contact-id')) { + logger('no contact: post ignored'); continue; + } $datarray['verb'] = ACTIVITY_POST; if($wall) { @@ -759,8 +761,10 @@ function fb_consume_stream($uid,$j,$wall = false) { intval($top_item), intval($uid) ); - if(count($r)) + if(count($r)) { $orig_post = $r[0]; + logger('fb: new top level item posted'); + } } if(isset($entry->likes) && isset($entry->likes->data)) diff --git a/include/items.php b/include/items.php index cbf5e4d24d..fbcac30cdf 100644 --- a/include/items.php +++ b/include/items.php @@ -742,6 +742,15 @@ function item_store($arr,$force_parent = false) { $arr['uri'], // already dbesc'd intval($arr['uid']) ); + if(! count($r)) { + // This is not good, but perhaps we encountered a rare race/cache condition, so back off and try again. + sleep(3); + $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", + $arr['uri'], // already dbesc'd + intval($arr['uid']) + ); + } + if(count($r)) { $current_post = $r[0]['id']; logger('item_store: created item ' . $current_post);