aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriendika <info@friendika.com>2011-10-12 02:21:18 -0700
committerFriendika <info@friendika.com>2011-10-12 02:21:18 -0700
commit3db43d5a39813f852bad8f4fe90e4c27400b7fae (patch)
tree07f860c35e66c2fb88f624bb3eb2247428d8357b
parentdf7702709b07560af1d469f0835586af317f39b0 (diff)
downloadvolse-hubzilla-3db43d5a39813f852bad8f4fe90e4c27400b7fae.tar.gz
volse-hubzilla-3db43d5a39813f852bad8f4fe90e4c27400b7fae.tar.bz2
volse-hubzilla-3db43d5a39813f852bad8f4fe90e4c27400b7fae.zip
storage race condition
-rw-r--r--include/items.php25
1 files changed, 17 insertions, 8 deletions
diff --git a/include/items.php b/include/items.php
index 4862ca578..2c23c6f1b 100644
--- a/include/items.php
+++ b/include/items.php
@@ -677,7 +677,7 @@ function item_store($arr,$force_parent = false) {
if($arr['gravity'])
$arr['gravity'] = intval($arr['gravity']);
- elseif($arr['parent-uri'] == $arr['uri'])
+ elseif($arr['parent-uri'] === $arr['uri'])
$arr['gravity'] = 0;
elseif(activity_match($arr['verb'],ACTIVITY_POST))
$arr['gravity'] = 6;
@@ -744,7 +744,7 @@ function item_store($arr,$force_parent = false) {
// find the parent and snarf the item id and ACL's
// and anything else we need to inherit
- $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+ $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d ORDER BY `id` ASC LIMIT 1",
dbesc($arr['parent-uri']),
intval($arr['uid'])
);
@@ -758,7 +758,8 @@ function item_store($arr,$force_parent = false) {
if($r[0]['uri'] != $r[0]['parent-uri']) {
$arr['thr-parent'] = $arr['parent-uri'];
$arr['parent-uri'] = $r[0]['parent-uri'];
- $z = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `parent-uri` = '%s' AND `uid` = %d LIMIT 1",
+ $z = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `parent-uri` = '%s' AND `uid` = %d
+ ORDER BY `id` ASC LIMIT 1",
dbesc($r[0]['parent-uri']),
dbesc($r[0]['parent-uri']),
intval($arr['uid'])
@@ -796,7 +797,7 @@ function item_store($arr,$force_parent = false) {
$r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($arr['uri']),
- dbesc($arr['uid'])
+ intval($arr['uid'])
);
if($r && count($r)) {
logger('item-store: duplicate item ignored. ' . print_r($arr,true));
@@ -817,14 +818,14 @@ function item_store($arr,$force_parent = false) {
// find the item we just created
- $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+ $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1 ORDER BY `id` ASC",
$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",
+ $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1 ORDER BY `id` ASC",
$arr['uri'], // already dbesc'd
intval($arr['uid'])
);
@@ -838,6 +839,14 @@ function item_store($arr,$force_parent = false) {
logger('item_store: could not locate created item');
return 0;
}
+ if(count($r) > 1) {
+ logger('item_store: duplicated post occurred. Removing duplicates.');
+ q("DELETE FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `id` != %d ",
+ $arr['uri'],
+ intval($arr['uid']),
+ intval($current_post)
+ );
+ }
if((! $parent_id) || ($arr['parent-uri'] === $arr['uri']))
$parent_id = $current_post;
@@ -2398,8 +2407,8 @@ function atom_entry($item,$type,$author,$owner,$comment = false) {
if(strlen($item['owner-name']))
$o .= atom_author('dfrn:owner',$item['owner-name'],$item['owner-link'],80,80,$item['owner-avatar']);
- if($item['parent'] != $item['id'])
- $o .= '<thr:in-reply-to ref="' . xmlify($item['parent-uri']) . '" type="text/html" href="' . xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']) . '" />' . "\r\n";
+ if(($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']))
+ $o .= '<thr:in-reply-to ref="' . xmlify($item['parent-uri']) . '" type="text/html" href="' . xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['parent']) . '" />' . "\r\n";
$o .= '<id>' . xmlify($item['uri']) . '</id>' . "\r\n";
$o .= '<title>' . xmlify($item['title']) . '</title>' . "\r\n";