mirror of
https://github.com/friendica/friendica
synced 2025-01-18 16:24:27 +00:00
Merge pull request #14256 from annando/network-seen
Set posts "seen" by a worker if too much rows are unseen
This commit is contained in:
commit
9e84a952fd
2 changed files with 50 additions and 14 deletions
|
@ -47,10 +47,12 @@ use Friendica\Core\L10n;
|
||||||
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
|
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||||
|
use Friendica\Core\Worker;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Circle;
|
use Friendica\Model\Circle;
|
||||||
|
use Friendica\Model\Post;
|
||||||
use Friendica\Model\Profile;
|
use Friendica\Model\Profile;
|
||||||
use Friendica\Module\Response;
|
use Friendica\Module\Response;
|
||||||
use Friendica\Module\Security\Login;
|
use Friendica\Module\Security\Login;
|
||||||
|
@ -231,7 +233,7 @@ class Network extends Timeline
|
||||||
} else {
|
} else {
|
||||||
$items = $this->getItems();
|
$items = $this->getItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
$o .= $this->conversation->render($items, Conversation::MODE_NETWORK, false, false, $this->getOrder(), $this->session->getLocalUserId());
|
$o .= $this->conversation->render($items, Conversation::MODE_NETWORK, false, false, $this->getOrder(), $this->session->getLocalUserId());
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$o .= $this->l10n->t('Error %d (%s) while fetching the timeline.', $e->getCode(), $e->getMessage());
|
$o .= $this->l10n->t('Error %d (%s) while fetching the timeline.', $e->getCode(), $e->getMessage());
|
||||||
|
@ -470,23 +472,20 @@ class Network extends Timeline
|
||||||
$items = array_reverse($items);
|
$items = array_reverse($items);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->database->isResult($items)) {
|
if ($this->ping || !$this->database->isResult($items)) {
|
||||||
$parents = array_column($items, 'uri-id');
|
return $items;
|
||||||
} else {
|
|
||||||
$parents = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We aren't going to try and figure out at the item, circle, and page
|
$this->setItemsSeenByCondition(['unseen' => true, 'uid' => $this->session->getLocalUserId(), 'parent-uri-id' => array_column($items, 'uri-id')]);
|
||||||
// level which items you've seen and which you haven't. If you're looking
|
|
||||||
// at the top level network page just mark everything seen.
|
$posts = Post::selectToArray(['uri-id'], ['unseen' => true, 'uid' => $this->session->getLocalUserId()], ['limit' => 100]);
|
||||||
if (!$this->circleId && !$this->star && !$this->mention) {
|
if (!empty($posts)) {
|
||||||
$condition = ['unseen' => true, 'uid' => $this->session->getLocalUserId()];
|
$this->setItemsSeenByCondition(['unseen' => true, 'uid' => $this->session->getLocalUserId(), 'uri-id' => array_column($posts, 'uri-id')]);
|
||||||
$this->setItemsSeenByCondition($condition);
|
|
||||||
} elseif (!empty($parents)) {
|
|
||||||
$condition = ['unseen' => true, 'uid' => $this->session->getLocalUserId(), 'parent-uri-id' => $parents];
|
|
||||||
$this->setItemsSeenByCondition($condition);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (count($posts) == 100) {
|
||||||
|
Worker::add(Worker::PRIORITY_MEDIUM, 'SetSeen', $this->session->getLocalUserId());
|
||||||
|
}
|
||||||
return $items;
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
37
src/Worker/SetSeen.php
Normal file
37
src/Worker/SetSeen.php
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright Copyright (C) 2010-2024, the Friendica project
|
||||||
|
*
|
||||||
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Friendica\Worker;
|
||||||
|
|
||||||
|
use Friendica\Core\Logger;
|
||||||
|
use Friendica\Model\Item;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set posts seen for the given user.
|
||||||
|
*/
|
||||||
|
class SetSeen
|
||||||
|
{
|
||||||
|
public static function execute(int $uid)
|
||||||
|
{
|
||||||
|
$ret = Item::update(['unseen' => false], ['unseen' => true, 'uid' => $uid]);
|
||||||
|
Logger::debug('Set seen', ['uid' => $uid, 'ret' => $ret]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue