Use the Item class instead of DBA calls when possible (#705)

pull/706/head
Michael Vogel 2018-08-15 07:23:53 +02:00 committed by Tobias Diekershoff
parent fd1eed17ab
commit 28b699573c
3 changed files with 11 additions and 17 deletions

View File

@ -955,7 +955,7 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion =
} }
$condition = ['verb' => ACTIVITY_LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']]; $condition = ['verb' => ACTIVITY_LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']];
if (DBA::exists('item', $condition)) { if (Item::exists($condition)) {
logger("pumpio_dolike: found existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']); logger("pumpio_dolike: found existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']);
return; return;
} }
@ -1084,13 +1084,13 @@ function pumpio_dodelete(App $a, $uid, $self, $post, $own_id)
{ {
// Two queries for speed issues // Two queries for speed issues
$condition = ['uri' => $post->object->id, 'uid' => $uid]; $condition = ['uri' => $post->object->id, 'uid' => $uid];
if (DBA::exists('item', $condition)) { if (Item::exists($condition)) {
Item::delete($condition); Item::delete($condition);
return true; return true;
} }
$condition = ['extid' => $post->object->id, 'uid' => $uid]; $condition = ['extid' => $post->object->id, 'uid' => $uid];
if (DBA::exists('item', $condition)) { if (Item::exists($condition)) {
Item::delete($condition); Item::delete($condition);
return true; return true;
} }
@ -1115,10 +1115,10 @@ function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcomp
if ($post->verb != "update") { if ($post->verb != "update") {
// Two queries for speed issues // Two queries for speed issues
if (DBA::exists('item', ['uri' => $post->object->id, 'uid' => $uid])) { if (Item::exists(['uri' => $post->object->id, 'uid' => $uid])) {
return false; return false;
} }
if (DBA::exists('item', ['extid' => $post->object->id, 'uid' => $uid])) { if (Item::exists(['extid' => $post->object->id, 'uid' => $uid])) {
return false; return false;
} }
} }
@ -1659,11 +1659,11 @@ function pumpio_fetchallcomments(App $a, $uid, $id)
} }
// Checking if the comment already exists - Two queries for speed issues // Checking if the comment already exists - Two queries for speed issues
if (DBA::exists('item', ['uri' => $item->id, 'uid' => $uid])) { if (Item::exists(['uri' => $item->id, 'uid' => $uid])) {
continue; continue;
} }
if (DBA::exists('item', ['extid' => $item->id, 'uid' => $uid])) { if (Item::exists(['extid' => $item->id, 'uid' => $uid])) {
continue; continue;
} }

View File

@ -1079,7 +1079,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex
$postarray['uri'] = $hostname . "::" . $content->id; $postarray['uri'] = $hostname . "::" . $content->id;
if (DBA::exists('item', ['extid' => $postarray['uri'], 'uid' => $uid])) { if (Item::exists(['extid' => $postarray['uri'], 'uid' => $uid])) {
return []; return [];
} }

View File

@ -735,15 +735,9 @@ function twitter_expire(App $a)
return; return;
} }
$r = DBA::select('item', ['id', 'iaid', 'icid'], ['deleted' => true, 'network' => Protocol::TWITTER]); $r = Item::select(['id'], ['deleted' => true, 'network' => Protocol::TWITTER]);
while ($row = DBA::fetch($r)) { while ($row = DBA::fetch($r)) {
DBA::delete('item', ['id' => $row['id']]); DBA::delete('item', ['id' => $row['id']]);
if (!empty($row['iaid']) && !DBA::exists('item', ['iaid' => $row['iaid']])) {
DBA::delete('item-activity', ['id' => $row['iaid']]);
}
if (!empty($row['icid']) && !DBA::exists('item', ['icid' => $row['icid']])) {
DBA::delete('item-content', ['id' => $row['icid']]);
}
} }
DBA::close($r); DBA::close($r);
@ -1352,7 +1346,7 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl
$postarray['source'] = json_encode($post); $postarray['source'] = json_encode($post);
// Don't import our own comments // Don't import our own comments
if (DBA::exists('item', ['extid' => $postarray['uri'], 'uid' => $uid])) { if (Item::exists(['extid' => $postarray['uri'], 'uid' => $uid])) {
logger("Item with extid " . $postarray['uri'] . " found.", LOGGER_DEBUG); logger("Item with extid " . $postarray['uri'] . " found.", LOGGER_DEBUG);
return []; return [];
} }
@ -1530,7 +1524,7 @@ function twitter_fetchparentposts(App $a, $uid, $post, TwitterOAuth $connection,
break; break;
} }
if (DBA::exists('item', ['uri' => 'twitter::' . $post->id_str, 'uid' => $uid])) { if (Item::exists(['uri' => 'twitter::' . $post->id_str, 'uid' => $uid])) {
break; break;
} }