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
|
||||
*
|
||||
* @param string $id
|
||||
* @param int $since
|
||||
* @param int $limit
|
||||
*
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function postReplies(string $id): DataResponse {
|
||||
public function postReplies(string $id, int $since = 0, int $limit = 5): DataResponse {
|
||||
try {
|
||||
$this->initViewer(true);
|
||||
|
||||
return $this->success($this->streamService->getRepliesByParentId($id, true));
|
||||
return $this->success($this->streamService->getRepliesByParentId($id, $since, $limit, true));
|
||||
} catch (Exception $e) {
|
||||
return $this->fail($e);
|
||||
}
|
||||
|
|
|
@ -506,14 +506,18 @@ class CoreRequestBuilder {
|
|||
* @param int $since
|
||||
* @param int $limit
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws DateTimeException
|
||||
*/
|
||||
protected function limitPaginate(IQueryBuilder &$qb, int $since = 0, int $limit = 5) {
|
||||
try {
|
||||
if ($since > 0) {
|
||||
$dTime = new DateTime();
|
||||
$dTime->setTimestamp($since);
|
||||
$this->limitToDBFieldDateTime($qb, 'published_time', $dTime);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw new DateTimeException();
|
||||
}
|
||||
|
||||
$qb->setMaxResults($limit);
|
||||
$pf = $this->defaultSelectAlias;
|
||||
|
|
|
@ -257,18 +257,23 @@ class StreamRequest extends StreamRequestBuilder {
|
|||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param int $since
|
||||
* @param int $limit
|
||||
* @param bool $asViewer
|
||||
*
|
||||
* @return Stream[]
|
||||
* @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 === '') {
|
||||
throw new StreamNotFoundException();
|
||||
};
|
||||
|
||||
$qb = $this->getStreamSelectSql();
|
||||
$this->limitToInReplyTo($qb, $id);
|
||||
$this->limitPaginate($qb, $since, $limit);
|
||||
$this->leftJoinCacheActors($qb, 'attributed_to');
|
||||
|
||||
if ($asViewer) {
|
||||
|
@ -353,7 +358,7 @@ class StreamRequest extends StreamRequestBuilder {
|
|||
* @param int $limit
|
||||
*
|
||||
* @return Stream[]
|
||||
* @throws Exception
|
||||
* @throws DateTimeException
|
||||
*/
|
||||
public function getTimelineHome(Person $actor, int $since = 0, int $limit = 5): array {
|
||||
$qb = $this->getStreamSelectSql();
|
||||
|
@ -387,7 +392,7 @@ class StreamRequest extends StreamRequestBuilder {
|
|||
* @param int $limit
|
||||
*
|
||||
* @return Stream[]
|
||||
* @throws Exception
|
||||
* @throws DateTimeException
|
||||
*/
|
||||
public function getTimelineNotifications(Person $actor, int $since = 0, int $limit = 5): array {
|
||||
$qb = $this->getStreamSelectSql();
|
||||
|
@ -413,7 +418,7 @@ class StreamRequest extends StreamRequestBuilder {
|
|||
* @param int $limit
|
||||
*
|
||||
* @return Stream[]
|
||||
* @throws Exception
|
||||
* @throws DateTimeException
|
||||
*/
|
||||
public function getTimelineAccount(string $actorId, int $since = 0, int $limit = 5): array {
|
||||
$qb = $this->getStreamSelectSql();
|
||||
|
@ -439,7 +444,7 @@ class StreamRequest extends StreamRequestBuilder {
|
|||
* @param int $limit
|
||||
*
|
||||
* @return Stream[]
|
||||
* @throws Exception
|
||||
* @throws DateTimeException
|
||||
*/
|
||||
public function getTimelineDirect(Person $actor, int $since = 0, int $limit = 5): array {
|
||||
$qb = $this->getStreamSelectSql();
|
||||
|
@ -466,7 +471,7 @@ class StreamRequest extends StreamRequestBuilder {
|
|||
* @param bool $localOnly
|
||||
*
|
||||
* @return Stream[]
|
||||
* @throws Exception
|
||||
* @throws DateTimeException
|
||||
*/
|
||||
public function getTimelineGlobal(int $since = 0, int $limit = 5, bool $localOnly = true
|
||||
): array {
|
||||
|
@ -495,7 +500,7 @@ class StreamRequest extends StreamRequestBuilder {
|
|||
* @param bool $localOnly
|
||||
*
|
||||
* @return Stream[]
|
||||
* @throws Exception
|
||||
* @throws DateTimeException
|
||||
*/
|
||||
public function getTimelineLiked(int $since = 0, int $limit = 5, bool $localOnly = true): array {
|
||||
$qb = $this->getStreamSelectSql();
|
||||
|
@ -524,7 +529,7 @@ class StreamRequest extends StreamRequestBuilder {
|
|||
* @param int $limit
|
||||
*
|
||||
* @return Stream[]
|
||||
* @throws Exception
|
||||
* @throws DateTimeException
|
||||
*/
|
||||
public function getTimelineTag(Person $actor, string $hashtag, int $since = 0, int $limit = 5
|
||||
): array {
|
||||
|
|
|
@ -391,13 +391,15 @@ class StreamService {
|
|||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param int $since
|
||||
* @param int $limit
|
||||
* @param bool $asViewer
|
||||
*
|
||||
* @return Stream[]
|
||||
* @throws StreamNotFoundException
|
||||
*/
|
||||
public function getRepliesByParentId(string $id, bool $asViewer = false): array {
|
||||
return $this->streamRequest->getRepliesByParentId($id, $asViewer);
|
||||
public function getRepliesByParentId(string $id, int $since = 0, int $limit = 5, bool $asViewer = false): array {
|
||||
return $this->streamRequest->getRepliesByParentId($id, $since, $limit, $asViewer);
|
||||
}
|
||||
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue