From 4c7a197f4b879ea966437792574aa0bb86c7e977 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 13 Jul 2017 06:00:53 +0000 Subject: [PATCH] Avoid duplicate database errors when storing the conversations --- include/items.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/include/items.php b/include/items.php index 5eb254b1e2..1e11c08c4b 100644 --- a/include/items.php +++ b/include/items.php @@ -6,6 +6,7 @@ use Friendica\App; use Friendica\ParseUrl; +use Friendica\Util\Lock; require_once 'include/bbcode.php'; require_once 'include/oembed.php'; @@ -444,6 +445,15 @@ function store_conversation($arr) { $conversation['source'] = $arr['source']; } + if (!Lock::set('store_conversation')) { + // When using semaphores, this case never can't happen + unset($arr['conversation-uri']); + unset($arr['conversation-href']); + unset($arr['protocol']); + unset($arr['source']); + return $arr; + } + $old_conv = dba::fetch_first("SELECT `item-uri`, `reply-to-uri`, `conversation-uri`, `conversation-href`, `protocol`, `source` FROM `conversation` WHERE `item-uri` = ?", $conversation['item-uri']); if (dbm::is_result($old_conv)) { @@ -465,6 +475,7 @@ function store_conversation($arr) { logger('Conversation: insert for '.$conversation['item-uri'].' (protocol '.$conversation['protocol'].') failed', LOGGER_DEBUG); } } + Lock::remove('store_conversation'); } unset($arr['conversation-uri']); @@ -2317,7 +2328,7 @@ function drop_item($id, $interactive = true) { } - +/// @todo: This query seems to be really slow function first_post_date($uid, $wall = false) { $r = q("SELECT `id`, `created` FROM `item` WHERE `uid` = %d AND `wall` = %d AND `deleted` = 0 AND `visible` = 1 AND `moderated` = 0 -- 2.39.5