refine the subscription loading time (fix #178) #181

Merged
Xefir merged 4 commits from metrics into main 2024-10-23 21:46:31 +00:00
2 changed files with 46 additions and 1 deletions
Showing only changes of commit 427c6b2ee8 - Show all commits

View File

@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace OCA\RePod\Controller;
use OCA\GPodderSync\Core\PodcastData\PodcastDataReader;
use OCA\GPodderSync\Core\PodcastData\PodcastMetricsReader;
use OCA\RePod\AppInfo\Application;
use OCA\RePod\Service\UserService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
class MetricsController extends Controller
{
public function __construct(
IRequest $request,
private PodcastDataReader $podcastDataReader,
private PodcastMetricsReader $podcastMetricsReader,
private UserService $userService
) {
parent::__construct(Application::APP_ID, $request);
}
#[NoAdminRequired]
#[NoCSRFRequired]
#[FrontpageRoute(verb: 'GET', url: '/metrics')]
public function index(): JSONResponse {
$subscriptions = $this->podcastMetricsReader->metrics($this->userService->getUserUID());
foreach ($subscriptions as $id => $subscription) {
try {
$subscriptions[$id]['data'] = $this->podcastDataReader->getCachedOrFetchPodcastData($subscription->getUrl(), $this->userService->getUserUID());
} catch (\Exception $e) {
continue;
}
}
return new JSONResponse($subscriptions);
}
}

View File

@ -24,7 +24,7 @@ export const useSubscriptions = defineStore('subscriptions', {
} catch {}
const metrics = await axios.get<PersonalSettingsMetricsInterface>(
generateUrl('/apps/gpoddersync/personal_settings/metrics'),
generateUrl('/apps/repod/metrics'),
)
this.subs = [...metrics.data.subscriptions]