summaryrefslogtreecommitdiffstats
path: root/lib/Db
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2020-07-31 12:21:59 -0100
committerMaxence Lange <maxence@artificial-owl.com>2020-07-31 12:21:59 -0100
commit85780ffbbcda656840c56ddbbb038fe9a590f59f (patch)
tree8df7867931ccd47ecbd83eb1f112e02193e74b1f /lib/Db
parent445ad1587874dd4dbcbe7f930a9596d6ae6344ec (diff)
first throw of chunked table
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib/Db')
-rw-r--r--lib/Db/SocialCoreQueryBuilder.php44
-rw-r--r--lib/Db/SocialCrossQueryBuilder.php6
-rw-r--r--lib/Db/SocialLimitsQueryBuilder.php1
-rw-r--r--lib/Db/StreamRequest.php1
4 files changed, 51 insertions, 1 deletions
diff --git a/lib/Db/SocialCoreQueryBuilder.php b/lib/Db/SocialCoreQueryBuilder.php
index 917a2b1c..d47712da 100644
--- a/lib/Db/SocialCoreQueryBuilder.php
+++ b/lib/Db/SocialCoreQueryBuilder.php
@@ -33,6 +33,7 @@ namespace OCA\Social\Db;
use daita\MySmallPhpTools\Db\ExtendedQueryBuilder;
use OCA\Social\Model\ActivityPub\Actor\Person;
+use OCP\DB\QueryBuilder\ICompositeExpression;
/**
@@ -47,6 +48,49 @@ class SocialCoreQueryBuilder extends ExtendedQueryBuilder {
private $viewer = null;
+ /** @var int */
+ private $chunk = 0;
+
+
+ /**
+ * @param int $chunk
+ *
+ * @return $this
+ */
+ public function setChunk(int $chunk): self {
+ $this->chunk = $chunk;
+ $this->inChunk();
+
+ return $this;
+ }
+
+ /**
+ * @return int
+ */
+ public function getChunk(): int {
+ return $this->chunk;
+ }
+
+ /**
+ * Limit the request to a chunk
+ *
+ * @param string $alias
+ * @param ICompositeExpression|null $expr
+ */
+ public function inChunk(string $alias = '', ICompositeExpression $expr = null) {
+ if ($this->getChunk() === 0) {
+ return;
+ }
+
+ if ($expr !== null) {
+ $expr->add($this->exprLimitToDBFieldInt('chunk', $this->getChunk(), $alias));
+
+ return;
+ }
+ $this->limitToDBFieldInt('chunk', $this->getChunk(), $alias);
+ }
+
+
/**
* @return bool
*/
diff --git a/lib/Db/SocialCrossQueryBuilder.php b/lib/Db/SocialCrossQueryBuilder.php
index 4cd50c5d..c0207ef5 100644
--- a/lib/Db/SocialCrossQueryBuilder.php
+++ b/lib/Db/SocialCrossQueryBuilder.php
@@ -55,6 +55,7 @@ class SocialCrossQueryBuilder extends SocialCoreQueryBuilder {
if ($aliasDest !== '') {
$this->from(CoreRequestBuilder::TABLE_STREAM_DEST, $aliasDest);
+// $this->inChunk($aliasDest);
}
if ($aliasFollowing !== '') {
$this->from(CoreRequestBuilder::TABLE_FOLLOWS, $aliasFollowing);
@@ -178,13 +179,16 @@ class SocialCrossQueryBuilder extends SocialCoreQueryBuilder {
$orX->add($expr->eq($alias . '.stream_id_prim', $pf . '.object_id_prim'));
$on = $expr->andX();
+// $this->inChunk('sa', $on);
$viewer = $this->getViewer();
$idPrim = $this->prim($viewer->getId());
$on->add($expr->eq($alias . '.actor_id_prim', $this->createNamedParameter($idPrim)));
$on->add($orX);
- $this->leftJoin($this->getDefaultSelectAlias(), CoreRequestBuilder::TABLE_STREAM_ACTIONS, 'sa', $on);
+ $this->leftJoin(
+ $this->getDefaultSelectAlias(), CoreRequestBuilder::TABLE_STREAM_ACTIONS, $alias, $on
+ );
}
diff --git a/lib/Db/SocialLimitsQueryBuilder.php b/lib/Db/SocialLimitsQueryBuilder.php
index c1dc173e..09455e40 100644
--- a/lib/Db/SocialLimitsQueryBuilder.php
+++ b/lib/Db/SocialLimitsQueryBuilder.php
@@ -46,6 +46,7 @@ use OCP\DB\QueryBuilder\ICompositeExpression;
*/
class SocialLimitsQueryBuilder extends SocialCrossQueryBuilder {
+
/**
* Limit the request to the Type
*
diff --git a/lib/Db/StreamRequest.php b/lib/Db/StreamRequest.php
index 8591eeaf..620da0db 100644
--- a/lib/Db/StreamRequest.php
+++ b/lib/Db/StreamRequest.php
@@ -370,6 +370,7 @@ class StreamRequest extends StreamRequestBuilder {
*/
public function getTimelineHome(int $since = 0, int $limit = 5): array {
$qb = $this->getStreamSelectSql();
+ $qb->setChunk(1);
$qb->filterType(SocialAppNotification::TYPE);
$qb->limitPaginate($since, $limit);