summaryrefslogtreecommitdiffstats
path: root/lib/Db
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2020-09-03 17:49:55 -0100
committerMaxence Lange <maxence@artificial-owl.com>2020-09-03 17:49:55 -0100
commitc827dd3ef2ec0d2ed475f65c8f70471b0ad6788b (patch)
treec2d50ff00619cb8dd448bfba33d1d8b59d0f1497 /lib/Db
parent3cc446aa9d39d209d2d96d92783e92120a4a7f52 (diff)
better navigation
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib/Db')
-rw-r--r--lib/Db/SocialLimitsQueryBuilder.php31
-rw-r--r--lib/Db/StreamRequest.php36
2 files changed, 66 insertions, 1 deletions
diff --git a/lib/Db/SocialLimitsQueryBuilder.php b/lib/Db/SocialLimitsQueryBuilder.php
index 16a8bd04..5a356a26 100644
--- a/lib/Db/SocialLimitsQueryBuilder.php
+++ b/lib/Db/SocialLimitsQueryBuilder.php
@@ -36,6 +36,7 @@ use DateInterval;
use DateTime;
use Exception;
use OCA\Social\Model\ActivityPub\ACore;
+use OCA\Social\Model\Client\Options\TimelineOptions;
use OCP\DB\QueryBuilder\ICompositeExpression;
@@ -323,10 +324,40 @@ class SocialLimitsQueryBuilder extends SocialCrossQueryBuilder {
/**
+ * @param TimelineOptions $options
+ *
+ */
+ public function paginate(TimelineOptions $options) {
+ $expr = $this->expr();
+ $pf = $this->getDefaultSelectAlias();
+
+ if ($options->getSinceId() > 0) {
+ $this->andWhere($expr->gt($pf . '.nid', $this->createNamedParameter($options->getSinceId())));
+ }
+
+ $options->setMinId(16000);
+ if ($options->getMaxId() > 0) {
+ $this->andWhere($expr->lt($pf . '.nid', $this->createNamedParameter($options->getMaxId())));
+ }
+
+ if ($options->getMinId() > 0) {
+ $options->setInverted(true);
+ $this->andWhere($expr->gt($pf . '.nid', $this->createNamedParameter($options->getMaxId())));
+ }
+
+
+ //TODO : manage min_id: Return results immediately newer than id
+ $this->setMaxResults($options->getLimit());
+ $this->orderBy($pf . '.nid', ($options->isInverted()) ? 'asc' : 'desc');
+ }
+
+
+ /**
* @param int $since
* @param int $limit
*
* @throws DateTimeException
+ * @deprecated - use paginate()
*/
public function limitPaginate(int $since = 0, int $limit = 5) {
try {
diff --git a/lib/Db/StreamRequest.php b/lib/Db/StreamRequest.php
index 1ab0cc5b..8ccfe6b1 100644
--- a/lib/Db/StreamRequest.php
+++ b/lib/Db/StreamRequest.php
@@ -42,6 +42,7 @@ use OCA\Social\Model\ActivityPub\Internal\SocialAppNotification;
use OCA\Social\Model\ActivityPub\Object\Document;
use OCA\Social\Model\ActivityPub\Object\Note;
use OCA\Social\Model\ActivityPub\Stream;
+use OCA\Social\Model\Client\Options\TimelineOptions;
use OCA\Social\Service\ConfigService;
use OCA\Social\Service\MiscService;
use OCP\DB\QueryBuilder\IQueryBuilder;
@@ -382,6 +383,38 @@ class StreamRequest extends StreamRequestBuilder {
* * Own posts,
* * Followed accounts
*
+ * @param TimelineOptions $options
+ *
+ * @return Stream[]
+ */
+ public function getTimelineHome(TimelineOptions $options): array {
+ $qb = $this->getStreamSelectSql($options->getFormat());
+ $qb->setChunk(1);
+
+ $qb->filterType(SocialAppNotification::TYPE);
+ $qb->paginate($options);
+
+ $qb->limitToViewer('sd', 'f', false);
+ $this->timelineHomeLinkCacheActor($qb, 'ca', 'f');
+
+ $qb->leftJoinStreamAction('sa');
+ $qb->filterDuplicate();
+
+ $result = $this->getStreamsFromRequest($qb);
+ if ($options->isInverted()) {
+ $result = array_reverse($result);
+ }
+
+ return $result;
+ }
+
+
+ /**
+ * Should returns:
+ * * Own posts,
+ * * Followed accounts
+ *
+ * @deprecated - use GetTimeline()
* @param int $since
* @param int $limit
* @param int $format
@@ -389,7 +422,8 @@ class StreamRequest extends StreamRequestBuilder {
* @return Stream[]
* @throws DateTimeException
*/
- public function getTimelineHome(int $since = 0, int $limit = 5, int $format = Stream::FORMAT_ACTIVITYPUB
+ public function getTimelineHome_dep(
+ int $since = 0, int $limit = 5, int $format = Stream::FORMAT_ACTIVITYPUB
): array {
$qb = $this->getStreamSelectSql($format);
$qb->setChunk(1);