X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2FModel%2FPost%2FEngagement.php;h=81ba6250233dfd7166d124777eb1473ea3e08dd3;hb=fdaff4303952427f222ee21f6b501d5087e25932;hp=84d106b7abe4654b774fb3eddf33a893189eda8e;hpb=5c166be3fca9ae803c616cd9024eb13e7a4b9156;p=friendica.git diff --git a/src/Model/Post/Engagement.php b/src/Model/Post/Engagement.php index 84d106b7ab..81ba625023 100644 --- a/src/Model/Post/Engagement.php +++ b/src/Model/Post/Engagement.php @@ -25,7 +25,7 @@ use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Database\Database; use Friendica\Database\DBA; -use Friendica\Model\Contact; +use Friendica\DI; use Friendica\Model\Item; use Friendica\Model\Post; use Friendica\Model\Verb; @@ -36,6 +36,12 @@ use Friendica\Util\DateTimeFormat; class Engagement { + /** + * Store engagement data from an item array + * + * @param array $item + * @return void + */ public static function storeFromItem(array $item) { if (!in_array($item['network'], Protocol::FEDERATED)) { @@ -58,25 +64,20 @@ class Engagement return; } - $parent = Post::selectFirst(['created', 'author-id', 'uid', 'private', 'contact-contact-type'], ['uri-id' => $item['parent-uri-id']]); + $parent = Post::selectFirst(['created', 'owner-id', 'uid', 'private', 'contact-contact-type'], ['uri-id' => $item['parent-uri-id']]); if ($parent['private'] != Item::PUBLIC) { Logger::debug('Non public posts are not stored', ['uri-id' => $item['uri-id'], 'parent-uri-id' => $item['parent-uri-id'], 'uid' => $parent['uid'], 'private' => $parent['private']]); return; } - if ($parent['contact-contact-type'] == Contact::TYPE_COMMUNITY) { - Logger::debug('Group posts are not stored', ['uri-id' => $item['uri-id'], 'parent-uri-id' => $item['parent-uri-id'], 'author-id' => $parent['author-id']]); - return; - } - - if ($parent['created'] < DateTimeFormat::utc('now - 1 day')) { + if ($parent['created'] < DateTimeFormat::utc('now - ' . DI::config()->get('channel', 'engagement_hours') . ' hour')) { Logger::debug('Post is too old', ['uri-id' => $item['uri-id'], 'parent-uri-id' => $item['parent-uri-id'], 'created' => $parent['created']]); return; } $engagement = [ 'uri-id' => $item['parent-uri-id'], - 'author-id' => $parent['author-id'], + 'owner-id' => $parent['owner-id'], 'contact-type' => $parent['contact-contact-type'], 'created' => $parent['created'], 'comments' => DBA::count('post', ['parent-uri-id' => $item['parent-uri-id'], 'gravity' => Item::GRAVITY_COMMENT]), @@ -86,13 +87,22 @@ class Engagement Verb::getID(Activity::FOLLOW), Verb::getID(Activity::VIEW), Verb::getID(Activity::READ) ]) ]; + if (($engagement['comments'] == 0) && ($engagement['activities'] == 0)) { + Logger::debug('No comments nor activities. Engagement not stored', ['fields' => $engagement]); + return; + } $ret = DBA::insert('post-engagement', $engagement, Database::INSERT_UPDATE); Logger::debug('Engagement stored', ['fields' => $engagement, 'ret' => $ret]); } + /** + * Expire old engagement data + * + * @return void + */ public static function expire() { - DBA::delete('post-engagement', ["`created` < ?", DateTimeFormat::utc('now - 1 day')]); + DBA::delete('post-engagement', ["`created` < ?", DateTimeFormat::utc('now - ' . DI::config()->get('channel', 'engagement_hours') . ' hour')]); Logger::notice('Cleared expired engagements', ['rows' => DBA::affectedRows()]); } }