New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved handling of native quotes #12076
Conversation
src/Content/Item.php
Outdated
$link = $post['plink'] ?: $post['uri']; | ||
$body .= "\n♲ " . $link; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Energy is expensive, let's save the creation of an intermediary variable.
$link = $post['plink'] ?: $post['uri']; | |
$body .= "\n♲ " . $link; | |
$body .= "\n♲ " . ($post['plink'] ?: $post['uri']); |
src/Model/Item.php
Outdated
if (!empty($shared['guid'])) { | ||
$shared_item = Post::selectFirst(['uri-id'], ['guid' => $shared['guid'], 'uid' => [0, $uid]]); | ||
if (!empty($shared_item['uri-id'])) { | ||
Logger::debug('Found post by guid', ['guid' => $shared['guid'], 'uid' => $uid]); | ||
} | ||
} | ||
|
||
if (empty($shared_item['uri-id']) && !empty($shared['message_id'])) { | ||
$shared_item = Post::selectFirst(['uri-id'], ['uri' => $shared['message_id'], 'uid' => [0, $uid]]); | ||
if (!empty($shared_item['uri-id'])) { | ||
Logger::debug('Found post by message_id', ['message_id' => $shared['message_id'], 'uid' => $uid]); | ||
} | ||
} | ||
|
||
if (empty($shared_item['uri-id']) && !empty($shared['link'])) { | ||
$shared_item = Post::selectFirst(['uri-id'], ['plink' => $shared['link'], 'uid' => [0, $uid]]); | ||
if (!empty($shared_item['uri-id'])) { | ||
Logger::debug('Found post by link', ['link' => $shared['link'], 'uid' => $uid]); | ||
} | ||
} | ||
|
||
if (empty($shared_item['uri-id'])) { | ||
$url = $shared['message_id'] ?: $shared['link']; | ||
$id = self::fetchByLink($url); | ||
if (!$id) { | ||
Logger::notice('Post could not be fetched.', ['url' => $url, 'uid' => $uid]); | ||
return 0; | ||
} | ||
|
||
Logger::debug('Fetched shared post', ['id' => $id, 'url' => $url, 'uid' => $uid]); | ||
|
||
$shared_item = Post::selectFirst(['uri-id'], ['id' => $id]); | ||
if (!DBA::isResult($shared_item)) { | ||
Logger::warning('Post does not exist.', ['id' => $id, 'url' => $url, 'uid' => $uid]); | ||
return 0; | ||
} | ||
} | ||
|
||
return $shared_item['uri-id']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather we used early returns than the repetitive empty($shared_item['uri-id'])
condition which means something different every time.
if (!empty($shared['guid'])) { | |
$shared_item = Post::selectFirst(['uri-id'], ['guid' => $shared['guid'], 'uid' => [0, $uid]]); | |
if (!empty($shared_item['uri-id'])) { | |
Logger::debug('Found post by guid', ['guid' => $shared['guid'], 'uid' => $uid]); | |
} | |
} | |
if (empty($shared_item['uri-id']) && !empty($shared['message_id'])) { | |
$shared_item = Post::selectFirst(['uri-id'], ['uri' => $shared['message_id'], 'uid' => [0, $uid]]); | |
if (!empty($shared_item['uri-id'])) { | |
Logger::debug('Found post by message_id', ['message_id' => $shared['message_id'], 'uid' => $uid]); | |
} | |
} | |
if (empty($shared_item['uri-id']) && !empty($shared['link'])) { | |
$shared_item = Post::selectFirst(['uri-id'], ['plink' => $shared['link'], 'uid' => [0, $uid]]); | |
if (!empty($shared_item['uri-id'])) { | |
Logger::debug('Found post by link', ['link' => $shared['link'], 'uid' => $uid]); | |
} | |
} | |
if (empty($shared_item['uri-id'])) { | |
$url = $shared['message_id'] ?: $shared['link']; | |
$id = self::fetchByLink($url); | |
if (!$id) { | |
Logger::notice('Post could not be fetched.', ['url' => $url, 'uid' => $uid]); | |
return 0; | |
} | |
Logger::debug('Fetched shared post', ['id' => $id, 'url' => $url, 'uid' => $uid]); | |
$shared_item = Post::selectFirst(['uri-id'], ['id' => $id]); | |
if (!DBA::isResult($shared_item)) { | |
Logger::warning('Post does not exist.', ['id' => $id, 'url' => $url, 'uid' => $uid]); | |
return 0; | |
} | |
} | |
return $shared_item['uri-id']; | |
if (!empty($shared['guid'])) { | |
$shared_item = Post::selectFirst(['uri-id'], ['guid' => $shared['guid'], 'uid' => [0, $uid]]); | |
if (!empty($shared_item['uri-id'])) { | |
Logger::debug('Found post by guid', ['guid' => $shared['guid'], 'uid' => $uid]); | |
return $shared_item['uri-id']; | |
} | |
} | |
if (!empty($shared['message_id'])) { | |
$shared_item = Post::selectFirst(['uri-id'], ['uri' => $shared['message_id'], 'uid' => [0, $uid]]); | |
if (!empty($shared_item['uri-id'])) { | |
Logger::debug('Found post by message_id', ['message_id' => $shared['message_id'], 'uid' => $uid]); | |
return $shared_item['uri-id']; | |
} | |
} | |
if (!empty($shared['link'])) { | |
$shared_item = Post::selectFirst(['uri-id'], ['plink' => $shared['link'], 'uid' => [0, $uid]]); | |
if (!empty($shared_item['uri-id'])) { | |
Logger::debug('Found post by link', ['link' => $shared['link'], 'uid' => $uid]); | |
return $shared_item['uri-id']; | |
} | |
} | |
$url = $shared['message_id'] ?: $shared['link']; | |
$id = self::fetchByLink($url); | |
if (!$id) { | |
Logger::notice('Post could not be fetched.', ['url' => $url, 'uid' => $uid]); | |
return 0; | |
} | |
Logger::debug('Fetched shared post', ['id' => $id, 'url' => $url, 'uid' => $uid]); | |
$shared_item = Post::selectFirst(['uri-id'], ['id' => $id]); | |
if (!DBA::isResult($shared_item)) { | |
Logger::warning('Post does not exist.', ['id' => $id, 'url' => $url, 'uid' => $uid]); | |
return 0; | |
} | |
return $shared_item['uri-id']; |
@MrPetovan changes are applied. |
src/Model/Item.php
Outdated
if (!DBA::isResult($shared_item)) { | ||
Logger::warning('Post does not exist.', ['id' => $id, 'url' => $url, 'uid' => $uid]); | ||
return 0; | ||
} else { | ||
Logger::debug('Fetched shared post', ['id' => $id, 'url' => $url, 'uid' => $uid]); | ||
} | ||
|
||
return $shared_item['uri-id']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there, no need for an else
statement here and we can avoid a negative condition.
if (!DBA::isResult($shared_item)) { | |
Logger::warning('Post does not exist.', ['id' => $id, 'url' => $url, 'uid' => $uid]); | |
return 0; | |
} else { | |
Logger::debug('Fetched shared post', ['id' => $id, 'url' => $url, 'uid' => $uid]); | |
} | |
return $shared_item['uri-id']; | |
if (DBA::isResult($shared_item)) { | |
Logger::debug('Fetched shared post', ['id' => $id, 'url' => $url, 'uid' => $uid]); | |
return $shared_item['uri-id']; | |
} | |
Logger::warning('Post does not exist.', ['id' => $id, 'url' => $url, 'uid' => $uid]); | |
return 0; |
Does this fix #12073 ? |
Yeah |
Did you see my second Change Request? |
We are now only storing non native quotes in the body. All native quotes are done via the quote-uri-id field in the post. The whole code is cleaned up around this.
This PR has to be merged at the same time as the addon PR.