sforkowany z mirror/social
add pagination
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>feature/noid/sql-rewrite-0929
rodzic
b1c50f91f6
commit
686f193c99
|
@ -220,14 +220,16 @@ class LocalController extends Controller {
|
||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
*
|
*
|
||||||
* @param string $id
|
* @param string $id
|
||||||
|
* @param int $since
|
||||||
|
* @param int $limit
|
||||||
*
|
*
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function postReplies(string $id): DataResponse {
|
public function postReplies(string $id, int $since = 0, int $limit = 5): DataResponse {
|
||||||
try {
|
try {
|
||||||
$this->initViewer(true);
|
$this->initViewer(true);
|
||||||
|
|
||||||
return $this->success($this->streamService->getRepliesByParentId($id, true));
|
return $this->success($this->streamService->getRepliesByParentId($id, $since, $limit, true));
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $this->fail($e);
|
return $this->fail($e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -506,13 +506,17 @@ class CoreRequestBuilder {
|
||||||
* @param int $since
|
* @param int $since
|
||||||
* @param int $limit
|
* @param int $limit
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws DateTimeException
|
||||||
*/
|
*/
|
||||||
protected function limitPaginate(IQueryBuilder &$qb, int $since = 0, int $limit = 5) {
|
protected function limitPaginate(IQueryBuilder &$qb, int $since = 0, int $limit = 5) {
|
||||||
if ($since > 0) {
|
try {
|
||||||
$dTime = new DateTime();
|
if ($since > 0) {
|
||||||
$dTime->setTimestamp($since);
|
$dTime = new DateTime();
|
||||||
$this->limitToDBFieldDateTime($qb, 'published_time', $dTime);
|
$dTime->setTimestamp($since);
|
||||||
|
$this->limitToDBFieldDateTime($qb, 'published_time', $dTime);
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
throw new DateTimeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$qb->setMaxResults($limit);
|
$qb->setMaxResults($limit);
|
||||||
|
|
|
@ -257,18 +257,23 @@ class StreamRequest extends StreamRequestBuilder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $id
|
* @param string $id
|
||||||
|
* @param int $since
|
||||||
|
* @param int $limit
|
||||||
* @param bool $asViewer
|
* @param bool $asViewer
|
||||||
*
|
*
|
||||||
* @return Stream[]
|
* @return Stream[]
|
||||||
* @throws StreamNotFoundException
|
* @throws StreamNotFoundException
|
||||||
|
* @throws DateTimeException
|
||||||
*/
|
*/
|
||||||
public function getRepliesByParentId(string $id, bool $asViewer = false): array {
|
public function getRepliesByParentId(string $id, int $since = 0, int $limit = 5, bool $asViewer = false
|
||||||
|
): array {
|
||||||
if ($id === '') {
|
if ($id === '') {
|
||||||
throw new StreamNotFoundException();
|
throw new StreamNotFoundException();
|
||||||
};
|
};
|
||||||
|
|
||||||
$qb = $this->getStreamSelectSql();
|
$qb = $this->getStreamSelectSql();
|
||||||
$this->limitToInReplyTo($qb, $id);
|
$this->limitToInReplyTo($qb, $id);
|
||||||
|
$this->limitPaginate($qb, $since, $limit);
|
||||||
$this->leftJoinCacheActors($qb, 'attributed_to');
|
$this->leftJoinCacheActors($qb, 'attributed_to');
|
||||||
|
|
||||||
if ($asViewer) {
|
if ($asViewer) {
|
||||||
|
@ -353,7 +358,7 @@ class StreamRequest extends StreamRequestBuilder {
|
||||||
* @param int $limit
|
* @param int $limit
|
||||||
*
|
*
|
||||||
* @return Stream[]
|
* @return Stream[]
|
||||||
* @throws Exception
|
* @throws DateTimeException
|
||||||
*/
|
*/
|
||||||
public function getTimelineHome(Person $actor, int $since = 0, int $limit = 5): array {
|
public function getTimelineHome(Person $actor, int $since = 0, int $limit = 5): array {
|
||||||
$qb = $this->getStreamSelectSql();
|
$qb = $this->getStreamSelectSql();
|
||||||
|
@ -387,7 +392,7 @@ class StreamRequest extends StreamRequestBuilder {
|
||||||
* @param int $limit
|
* @param int $limit
|
||||||
*
|
*
|
||||||
* @return Stream[]
|
* @return Stream[]
|
||||||
* @throws Exception
|
* @throws DateTimeException
|
||||||
*/
|
*/
|
||||||
public function getTimelineNotifications(Person $actor, int $since = 0, int $limit = 5): array {
|
public function getTimelineNotifications(Person $actor, int $since = 0, int $limit = 5): array {
|
||||||
$qb = $this->getStreamSelectSql();
|
$qb = $this->getStreamSelectSql();
|
||||||
|
@ -413,7 +418,7 @@ class StreamRequest extends StreamRequestBuilder {
|
||||||
* @param int $limit
|
* @param int $limit
|
||||||
*
|
*
|
||||||
* @return Stream[]
|
* @return Stream[]
|
||||||
* @throws Exception
|
* @throws DateTimeException
|
||||||
*/
|
*/
|
||||||
public function getTimelineAccount(string $actorId, int $since = 0, int $limit = 5): array {
|
public function getTimelineAccount(string $actorId, int $since = 0, int $limit = 5): array {
|
||||||
$qb = $this->getStreamSelectSql();
|
$qb = $this->getStreamSelectSql();
|
||||||
|
@ -439,7 +444,7 @@ class StreamRequest extends StreamRequestBuilder {
|
||||||
* @param int $limit
|
* @param int $limit
|
||||||
*
|
*
|
||||||
* @return Stream[]
|
* @return Stream[]
|
||||||
* @throws Exception
|
* @throws DateTimeException
|
||||||
*/
|
*/
|
||||||
public function getTimelineDirect(Person $actor, int $since = 0, int $limit = 5): array {
|
public function getTimelineDirect(Person $actor, int $since = 0, int $limit = 5): array {
|
||||||
$qb = $this->getStreamSelectSql();
|
$qb = $this->getStreamSelectSql();
|
||||||
|
@ -466,7 +471,7 @@ class StreamRequest extends StreamRequestBuilder {
|
||||||
* @param bool $localOnly
|
* @param bool $localOnly
|
||||||
*
|
*
|
||||||
* @return Stream[]
|
* @return Stream[]
|
||||||
* @throws Exception
|
* @throws DateTimeException
|
||||||
*/
|
*/
|
||||||
public function getTimelineGlobal(int $since = 0, int $limit = 5, bool $localOnly = true
|
public function getTimelineGlobal(int $since = 0, int $limit = 5, bool $localOnly = true
|
||||||
): array {
|
): array {
|
||||||
|
@ -495,7 +500,7 @@ class StreamRequest extends StreamRequestBuilder {
|
||||||
* @param bool $localOnly
|
* @param bool $localOnly
|
||||||
*
|
*
|
||||||
* @return Stream[]
|
* @return Stream[]
|
||||||
* @throws Exception
|
* @throws DateTimeException
|
||||||
*/
|
*/
|
||||||
public function getTimelineLiked(int $since = 0, int $limit = 5, bool $localOnly = true): array {
|
public function getTimelineLiked(int $since = 0, int $limit = 5, bool $localOnly = true): array {
|
||||||
$qb = $this->getStreamSelectSql();
|
$qb = $this->getStreamSelectSql();
|
||||||
|
@ -524,7 +529,7 @@ class StreamRequest extends StreamRequestBuilder {
|
||||||
* @param int $limit
|
* @param int $limit
|
||||||
*
|
*
|
||||||
* @return Stream[]
|
* @return Stream[]
|
||||||
* @throws Exception
|
* @throws DateTimeException
|
||||||
*/
|
*/
|
||||||
public function getTimelineTag(Person $actor, string $hashtag, int $since = 0, int $limit = 5
|
public function getTimelineTag(Person $actor, string $hashtag, int $since = 0, int $limit = 5
|
||||||
): array {
|
): array {
|
||||||
|
|
|
@ -391,13 +391,15 @@ class StreamService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $id
|
* @param string $id
|
||||||
|
* @param int $since
|
||||||
|
* @param int $limit
|
||||||
* @param bool $asViewer
|
* @param bool $asViewer
|
||||||
*
|
*
|
||||||
* @return Stream[]
|
* @return Stream[]
|
||||||
* @throws StreamNotFoundException
|
* @throws StreamNotFoundException
|
||||||
*/
|
*/
|
||||||
public function getRepliesByParentId(string $id, bool $asViewer = false): array {
|
public function getRepliesByParentId(string $id, int $since = 0, int $limit = 5, bool $asViewer = false): array {
|
||||||
return $this->streamRequest->getRepliesByParentId($id, $asViewer);
|
return $this->streamRequest->getRepliesByParentId($id, $since, $limit, $asViewer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue