mirror of
https://github.com/friendica/friendica
synced 2025-04-19 06:30:10 +00:00
Merge pull request #11759 from annando/enqueue-posts
Fetch missing posts via a queue
This commit is contained in:
commit
a5d679ea95
25 changed files with 908 additions and 362 deletions
|
@ -26,7 +26,6 @@ use Friendica\Core\Cache\Enum\Duration;
|
|||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Database\DBStructure;
|
||||
use Friendica\DI;
|
||||
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
|
||||
use Friendica\Network\HTTPException;
|
||||
|
@ -539,4 +538,28 @@ class APContact
|
|||
|
||||
HTTPSignature::setInboxStatus($url, true, $shared);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the apcontact is a relay account
|
||||
*
|
||||
* @param array $apcontact
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isRelay(array $apcontact): bool
|
||||
{
|
||||
if ($apcontact['nick'] != 'relay') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($apcontact['type'] == 'Application') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (in_array($apcontact['type'], ['Group', 'Service']) && is_null($apcontact['outbox'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ class Item
|
|||
// Field list that is used to display the items
|
||||
const DISPLAY_FIELDLIST = [
|
||||
'uid', 'id', 'parent', 'guid', 'network', 'gravity',
|
||||
'uri-id', 'uri', 'thr-parent-id', 'thr-parent', 'parent-uri-id', 'parent-uri',
|
||||
'uri-id', 'uri', 'thr-parent-id', 'thr-parent', 'parent-uri-id', 'parent-uri', 'conversation',
|
||||
'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink',
|
||||
'wall', 'private', 'starred', 'origin', 'parent-origin', 'title', 'body', 'language',
|
||||
'content-warning', 'location', 'coord', 'app', 'rendered-hash', 'rendered-html', 'object',
|
||||
|
@ -103,7 +103,7 @@ class Item
|
|||
|
||||
// Field list that is used to deliver items via the protocols
|
||||
const DELIVER_FIELDLIST = ['uid', 'id', 'parent', 'uri-id', 'uri', 'thr-parent', 'parent-uri', 'guid',
|
||||
'parent-guid', 'received', 'created', 'edited', 'verb', 'object-type', 'object', 'target',
|
||||
'parent-guid', 'conversation', 'received', 'created', 'edited', 'verb', 'object-type', 'object', 'target',
|
||||
'private', 'title', 'body', 'raw-body', 'location', 'coord', 'app',
|
||||
'inform', 'deleted', 'extid', 'post-type', 'post-reason', 'gravity',
|
||||
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
|
||||
|
@ -116,7 +116,7 @@ class Item
|
|||
|
||||
// All fields in the item table
|
||||
const ITEM_FIELDLIST = ['id', 'uid', 'parent', 'uri', 'parent-uri', 'thr-parent',
|
||||
'guid', 'uri-id', 'parent-uri-id', 'thr-parent-id', 'vid',
|
||||
'guid', 'uri-id', 'parent-uri-id', 'thr-parent-id', 'conversation', 'vid',
|
||||
'contact-id', 'wall', 'gravity', 'extid', 'psid',
|
||||
'created', 'edited', 'commented', 'received', 'changed', 'verb',
|
||||
'postopts', 'plink', 'resource-id', 'event-id', 'inform',
|
||||
|
@ -683,14 +683,19 @@ class Item
|
|||
'uri-id', 'parent-uri-id',
|
||||
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
|
||||
'wall', 'private', 'origin', 'author-id'];
|
||||
$condition = ['uri-id' => $item['thr-parent-id'], 'uid' => $item['uid']];
|
||||
$condition = ['uri-id' => [$item['thr-parent-id'], $item['parent-uri-id']], 'uid' => $item['uid']];
|
||||
$params = ['order' => ['id' => false]];
|
||||
$parent = Post::selectFirst($fields, $condition, $params);
|
||||
|
||||
if (!DBA::isResult($parent) && $item['origin']) {
|
||||
if (!DBA::isResult($parent) && Post::exists(['uri-id' => [$item['thr-parent-id'], $item['parent-uri-id']], 'uid' => 0])) {
|
||||
$stored = Item::storeForUserByUriId($item['thr-parent-id'], $item['uid']);
|
||||
Logger::info('Stored thread parent item for user', ['uri-id' => $item['thr-parent-id'], 'uid' => $item['uid'], 'stored' => $stored]);
|
||||
$parent = Post::selectFirst($fields, $condition, $params);
|
||||
if (!$stored && ($item['thr-parent-id'] != $item['parent-uri-id'])) {
|
||||
$stored = Item::storeForUserByUriId($item['parent-uri-id'], $item['uid']);
|
||||
}
|
||||
if ($stored) {
|
||||
Logger::info('Stored thread parent item for user', ['uri-id' => $item['thr-parent-id'], 'uid' => $item['uid'], 'stored' => $stored]);
|
||||
$parent = Post::selectFirst($fields, $condition, $params);
|
||||
}
|
||||
}
|
||||
|
||||
if (!DBA::isResult($parent)) {
|
||||
|
@ -787,10 +792,13 @@ class Item
|
|||
|
||||
// Backward compatibility: parent-uri used to be the direct parent uri.
|
||||
// If it is provided without a thr-parent, it probably is the old behavior.
|
||||
$item['thr-parent'] = trim($item['thr-parent'] ?? $item['parent-uri'] ?? $item['uri']);
|
||||
$item['parent-uri'] = $item['thr-parent'];
|
||||
if (empty($item['thr-parent']) || empty($item['parent-uri'])) {
|
||||
$item['thr-parent'] = trim($item['thr-parent'] ?? $item['parent-uri'] ?? $item['uri']);
|
||||
$item['parent-uri'] = $item['thr-parent'];
|
||||
}
|
||||
|
||||
$item['thr-parent-id'] = $item['parent-uri-id'] = ItemURI::getIdByURI($item['thr-parent']);
|
||||
$item['thr-parent-id'] = ItemURI::getIdByURI($item['thr-parent']);
|
||||
$item['parent-uri-id'] = ItemURI::getIdByURI($item['parent-uri']);
|
||||
|
||||
// Store conversation data
|
||||
$item = Conversation::insert($item);
|
||||
|
@ -900,7 +908,7 @@ class Item
|
|||
$item['contact-id'] = self::contactId($item);
|
||||
|
||||
if (!empty($item['direction']) && in_array($item['direction'], [Conversation::PUSH, Conversation::RELAY]) &&
|
||||
empty($item['origin']) &&self::isTooOld($item)) {
|
||||
empty($item['origin']) && self::isTooOld($item)) {
|
||||
Logger::info('Item is too old', ['item' => $item]);
|
||||
return 0;
|
||||
}
|
||||
|
@ -966,11 +974,19 @@ class Item
|
|||
} else {
|
||||
$parent_id = 0;
|
||||
$parent_origin = $item['origin'];
|
||||
|
||||
if ($item['wall'] && empty($item['conversation'])) {
|
||||
$item['conversation'] = $item['parent-uri'] . '#context';
|
||||
}
|
||||
}
|
||||
|
||||
$item['parent-uri-id'] = ItemURI::getIdByURI($item['parent-uri']);
|
||||
$item['thr-parent-id'] = ItemURI::getIdByURI($item['thr-parent']);
|
||||
|
||||
if (!empty($item['conversation']) && empty($item['conversation-id'])) {
|
||||
$item['conversation-id'] = ItemURI::getIdByURI($item['conversation']);
|
||||
}
|
||||
|
||||
// Is this item available in the global items (with uid=0)?
|
||||
if ($item['uid'] == 0) {
|
||||
$item['global'] = true;
|
||||
|
@ -3410,9 +3426,7 @@ class Item
|
|||
return is_numeric($hookData['item_id']) ? $hookData['item_id'] : 0;
|
||||
}
|
||||
|
||||
$fetchQueue = new ActivityPub\FetchQueue();
|
||||
$fetched_uri = ActivityPub\Processor::fetchMissingActivity($fetchQueue, $uri);
|
||||
$fetchQueue->process();
|
||||
$fetched_uri = ActivityPub\Processor::fetchMissingActivity($uri);
|
||||
|
||||
if ($fetched_uri) {
|
||||
$item_id = self::searchByLink($fetched_uri, $uid);
|
||||
|
|
|
@ -24,7 +24,6 @@ namespace Friendica\Model\Post;
|
|||
use Friendica\Database\DBA;
|
||||
use \BadMethodCallException;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBStructure;
|
||||
use Friendica\DI;
|
||||
|
||||
class User
|
||||
|
@ -44,10 +43,6 @@ class User
|
|||
throw new BadMethodCallException('Empty URI_id');
|
||||
}
|
||||
|
||||
if (DBA::exists('post-user', ['uri-id' => $uri_id, 'uid' => $uid])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$fields = DI::dbaDefinition()->truncateFieldsForTable('post-user', $data);
|
||||
|
||||
// Additionally assign the key fields
|
||||
|
@ -59,6 +54,33 @@ class User
|
|||
$fields['unseen'] = false;
|
||||
}
|
||||
|
||||
// Does the entry already exist?
|
||||
if (DBA::exists('post-user', ['uri-id' => $uri_id, 'uid' => $uid])) {
|
||||
$postuser = DBA::selectFirst('post-user', [], ['uri-id' => $uri_id, 'uid' => $uid]);
|
||||
|
||||
// We quit here, when there are obvious differences
|
||||
foreach (['created', 'owner-id', 'author-id', 'vid', 'network', 'private', 'wall', 'origin'] as $key) {
|
||||
if ($fields[$key] != $postuser[$key]) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
$update = [];
|
||||
foreach (['gravity', 'parent-uri-id', 'thr-parent-id'] as $key) {
|
||||
if ($fields[$key] != $postuser[$key]) {
|
||||
$update[$key] = $fields[$key];
|
||||
}
|
||||
}
|
||||
|
||||
// When the parents changed, we apply these changes to the existing entry
|
||||
if (!empty($update)) {
|
||||
DBA::update('post-user', $update, ['id' => $postuser['id']]);
|
||||
return $postuser['id'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!DBA::insert('post-user', $fields, Database::INSERT_IGNORE)) {
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue