[UI][TIMELINES] Refactored query for public stream

This commit is contained in:
João Brandão 2020-12-02 22:57:32 +00:00 committed by Hugo Sales
parent c36436c1a1
commit 5516a77b33
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
4 changed files with 22 additions and 2 deletions

View File

@ -37,6 +37,7 @@ use App\Core\Controller;
use App\Core\DB\DB;
use App\Core\Event;
use App\Core\NoteScope;
use App\Entity\Note;
use App\Util\Common;
use App\Util\Exception\ClientException;
use function App\Core\I18n\_m;
@ -61,7 +62,7 @@ class Network extends Controller
return [
'_template' => 'network/public.html.twig',
'notes' => $notes,
'notes' => Note::getAllNotes($this->instance_scope),
];
}

View File

@ -9,6 +9,7 @@ use function App\Core\I18n\_m;
use App\Entity\Follow;
use App\Entity\GSActor;
use App\Entity\LocalUser;
use App\Entity\Note;
use App\Security\Authenticator;
use App\Security\EmailVerifier;
use app\Util\Common;
@ -39,7 +40,7 @@ class Security extends Controller
// last username entered by the user
$last_username = $authenticationUtils->getLastUsername();
return ['_template' => 'security/login.html.twig', 'last_username' => $last_username, 'error' => $error];
return ['_template' => 'security/login.html.twig', 'last_username' => $last_username, 'error' => $error, 'notes' => Note::getAllNotes($this->instance_scope), ];
}
public function logout()
@ -133,6 +134,7 @@ class Security extends Controller
return [
'_template' => 'security/register.html.twig',
'registration_form' => $form->createView(),
'notes' => Note::getAllNotes($this->instance_scope),
];
}
}

View File

@ -199,6 +199,15 @@ class Note extends Entity
Event::handle('GetAvatarUrl', [$this->getActorNickname(), &$url]);
return $url;
}
public function getAllNotes(int $noteScope): array
{
return DB::sql('select * from note n ' .
'where n.reply_to is null and (n.scope & :notescope) <> 0 ' .
'order by n.created DESC',
['n' => 'App\Entity\Note'],
['notescope' => $noteScope]
);
}
public function getAttachments(): array
{

View File

@ -98,6 +98,14 @@ abstract class Common
}
}
public function getAllNotes(int $noteScope): array
{
return DB::sql('select * from note n ' .
"where n.reply_to is null and (n.scope & {$noteScope}) <> 0 " .
'order by n.created DESC',
['n' => 'App\Entity\Note']);
}
public static function ensureLoggedIn(): LocalUser
{
if (($user = self::user()) == null) {