revert: revert new subscriptions loading model (fix #182)

This commit is contained in:
Michel Roux 2024-10-24 23:42:22 +02:00
parent 668c377c33
commit 75aad7baab
13 changed files with 141 additions and 138 deletions

View File

@ -1,3 +1,9 @@
## 3.3.2 - What a Nightmare - 2024-10-24
### Fixed
- 🚑 Revert [#178](https://git.crystalyx.net/Xefir/repod/issues/178) not working on big subscriptions lists
[#182](https://git.crystalyx.net/Xefir/repod/issues/182) reported by @SteveDinn
## 3.3.1 - Breaking the Loop - 2024-10-24
### Changed

View File

@ -14,7 +14,7 @@
## Requirements
You need to have [GPodderSync](https://apps.nextcloud.com/apps/gpoddersync) installed to use this app!]]></description>
<version>3.3.1</version>
<version>3.3.2</version>
<licence>agpl</licence>
<author mail="xefir@crystalyx.net" homepage="https://crystalyx.net">Michel Roux</author>
<namespace>RePod</namespace>

18
composer.lock generated
View File

@ -1359,12 +1359,12 @@
"source": {
"type": "git",
"url": "https://github.com/Roave/SecurityAdvisories.git",
"reference": "51e3fa290bca57eca7ba6c261b8a1278eb13a98a"
"reference": "c9898eb8a4668430f8a40e7405340f47cd73d7c0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/51e3fa290bca57eca7ba6c261b8a1278eb13a98a",
"reference": "51e3fa290bca57eca7ba6c261b8a1278eb13a98a",
"url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/c9898eb8a4668430f8a40e7405340f47cd73d7c0",
"reference": "c9898eb8a4668430f8a40e7405340f47cd73d7c0",
"shasum": ""
},
"conflict": {
@ -1372,7 +1372,7 @@
"admidio/admidio": "<4.3.12",
"adodb/adodb-php": "<=5.20.20|>=5.21,<=5.21.3",
"aheinze/cockpit": "<2.2",
"aimeos/ai-admin-graphql": ">=2022.04.1,<2022.10.10|>=2023.04.1,<2023.10.6|>=2024.04.1,<2024.04.6",
"aimeos/ai-admin-graphql": ">=2022.04.1,<2022.10.10|>=2023.04.1,<2023.10.6|>=2024.04.1,<2024.07.2",
"aimeos/ai-admin-jsonadm": "<2020.10.13|>=2021.04.1,<2021.10.6|>=2022.04.1,<2022.10.3|>=2023.04.1,<2023.10.4|==2024.04.1",
"aimeos/ai-client-html": ">=2020.04.1,<2020.10.27|>=2021.04.1,<2021.10.22|>=2022.04.1,<2022.10.13|>=2023.04.1,<2023.10.15|>=2024.04.1,<2024.04.7",
"aimeos/ai-controller-frontend": "<2020.10.15|>=2021.04.1,<2021.10.8|>=2022.04.1,<2022.10.8|>=2023.04.1,<2023.10.9|==2024.04.1",
@ -1416,7 +1416,7 @@
"barrelstrength/sprout-forms": "<3.9",
"barryvdh/laravel-translation-manager": "<0.6.2",
"barzahlen/barzahlen-php": "<2.0.1",
"baserproject/basercms": "<5.0.9",
"baserproject/basercms": "<=5.1.1",
"bassjobsen/bootstrap-3-typeahead": ">4.0.2",
"bbpress/bbpress": "<2.6.5",
"bcosca/fatfree": "<3.7.2",
@ -1861,7 +1861,7 @@
"processwire/processwire": "<=3.0.229",
"propel/propel": ">=2.0.0.0-alpha1,<=2.0.0.0-alpha7",
"propel/propel1": ">=1,<=1.7.1",
"pterodactyl/panel": "<1.11.6",
"pterodactyl/panel": "<1.11.8",
"ptheofan/yii2-statemachine": ">=2.0.0.0-RC1-dev,<=2",
"ptrofimov/beanstalk_console": "<1.7.14",
"pubnub/pubnub": "<6.1",
@ -2183,7 +2183,7 @@
"type": "tidelift"
}
],
"time": "2024-10-21T20:05:20+00:00"
"time": "2024-10-24T20:05:29+00:00"
},
{
"name": "sebastian/diff",
@ -3210,8 +3210,8 @@
},
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"platform": {},
"platform-dev": {},
"platform-overrides": {
"php": "8.1"
},

View File

@ -1,51 +0,0 @@
<?php
declare(strict_types=1);
namespace OCA\RePod\Controller;
use OCA\GPodderSync\Core\PodcastData\PodcastDataReader;
use OCA\GPodderSync\Core\PodcastData\PodcastMetrics;
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 {
$metrics = $this->podcastMetricsReader->metrics($this->userService->getUserUID());
usort($metrics, fn (PodcastMetrics $a, PodcastMetrics $b) => $b->getListenedSeconds() <=> $a->getListenedSeconds());
$subscriptions = [];
foreach ($metrics as $metric) {
$subscription = $metric->toArray();
try {
$subscription['data'] = $this->podcastDataReader->getCachedOrFetchPodcastData($metric->getUrl(), $this->userService->getUserUID());
} catch (\Exception $e) {
}
$subscriptions[] = $subscription;
}
return new JSONResponse($subscriptions);
}
}

56
package-lock.json generated
View File

@ -19,7 +19,7 @@
"pinia": "^2.2.4",
"toastify-js": "^1.12.0",
"vite": "^5.4.10",
"vite-plugin-vue-devtools": "^7.5.3",
"vite-plugin-vue-devtools": "^7.5.4",
"vue": "^3.5.12",
"vue-material-design-icons": "^5.3.1",
"vue-router": "^4.4.5"
@ -583,9 +583,9 @@
}
},
"node_modules/@csstools/css-parser-algorithms": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/@csstools/css-parser-algorithms/-/css-parser-algorithms-3.0.2.tgz",
"integrity": "sha512-6tC/MnlEvs5suR4Ahef4YlBccJDHZuxGsAlxXmybWjZ5jPxlzLSMlRZ9mVHSRvlD+CmtE7+hJ+UQbfXrws/rUQ==",
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/@csstools/css-parser-algorithms/-/css-parser-algorithms-3.0.3.tgz",
"integrity": "sha512-15WQTALDyxAwSgAvLt7BksAssiSrNNhTv4zM7qX9U6R7FtpNskVVakzWQlYODlwPwXhGpKPmB10LM943pxMe7w==",
"dev": true,
"funding": [
{
@ -3213,13 +3213,13 @@
"license": "MIT"
},
"node_modules/@vue/devtools-core": {
"version": "7.5.3",
"resolved": "https://registry.npmjs.org/@vue/devtools-core/-/devtools-core-7.5.3.tgz",
"integrity": "sha512-KIzT76GPubhvvQzjQtf7yhaSdVOcq/0CV2QbUw2bf3vzV+biHsgfgQ1XEbPbPKuHr1t0zshj53mBv0bx2OmkJw==",
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/@vue/devtools-core/-/devtools-core-7.5.4.tgz",
"integrity": "sha512-igB2iUKsCUrXkp0wKLn3n5X8jz3AgXWk7if0QpLu3Do16QmlTO0e+/VvTpX0ZbLMh8OOAxDKyfPvJMMO/4QJ5w==",
"license": "MIT",
"dependencies": {
"@vue/devtools-kit": "^7.5.3",
"@vue/devtools-shared": "^7.5.3",
"@vue/devtools-kit": "^7.5.4",
"@vue/devtools-shared": "^7.5.4",
"mitt": "^3.0.1",
"nanoid": "^3.3.4",
"pathe": "^1.1.2",
@ -3230,12 +3230,12 @@
}
},
"node_modules/@vue/devtools-kit": {
"version": "7.5.3",
"resolved": "https://registry.npmjs.org/@vue/devtools-kit/-/devtools-kit-7.5.3.tgz",
"integrity": "sha512-XSTXCAHshYniK3gLQfhMRDuDLLj6vHFWKVl1tvtSgZ0iJy5AXoI4U/GKGlyS2uS1hwZCSoNSGdkKtbW/pn/Iuw==",
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/@vue/devtools-kit/-/devtools-kit-7.5.4.tgz",
"integrity": "sha512-0i7WFgc1B2TL52tstn82zlb9opSA0aIiHfkUYFXtZb8CIpmlFMTkHtgwVl6PMWNBj3LNhYou1YJCLpCYvJYYoA==",
"license": "MIT",
"dependencies": {
"@vue/devtools-shared": "^7.5.3",
"@vue/devtools-shared": "^7.5.4",
"birpc": "^0.2.19",
"hookable": "^5.5.3",
"mitt": "^3.0.1",
@ -3245,9 +3245,9 @@
}
},
"node_modules/@vue/devtools-shared": {
"version": "7.5.3",
"resolved": "https://registry.npmjs.org/@vue/devtools-shared/-/devtools-shared-7.5.3.tgz",
"integrity": "sha512-i2tCUtAEQ0S8AmTuy6FSOmVKCB5ajmMaVrrw0ypX75koLSo1mssQ8zezds5IoUZHRiXBsgoGHbJGuGwyrSGhqQ==",
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/@vue/devtools-shared/-/devtools-shared-7.5.4.tgz",
"integrity": "sha512-dwuq4YmwTyLc7eBOqX63s3JB8il7qnKsNgENglSMkUPwiItHkVAYYfPESN1rxSdYkl1RCux1l5TBidYqfUDNAA==",
"license": "MIT",
"dependencies": {
"rfdc": "^1.4.1"
@ -5043,9 +5043,9 @@
}
},
"node_modules/electron-to-chromium": {
"version": "1.5.43",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.43.tgz",
"integrity": "sha512-NxnmFBHDl5Sachd2P46O7UJiMaMHMLSofoIWVJq3mj8NJgG0umiSeljAVP9lGzjI0UDLJJ5jjoGjcrB8RSbjLQ==",
"version": "1.5.45",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.45.tgz",
"integrity": "sha512-vOzZS6uZwhhbkZbcRyiy99Wg+pYFV5hk+5YaECvx0+Z31NR3Tt5zS6dze2OepT6PCTzVzT0dIJItti+uAW5zmw==",
"license": "ISC"
},
"node_modules/elliptic": {
@ -10701,9 +10701,9 @@
}
},
"node_modules/sass": {
"version": "1.80.3",
"resolved": "https://registry.npmjs.org/sass/-/sass-1.80.3.tgz",
"integrity": "sha512-ptDWyVmDMVielpz/oWy3YP3nfs7LpJTHIJZboMVs8GEC9eUmtZTZhMHlTW98wY4aEorDfjN38+Wr/XjskFWcfA==",
"version": "1.80.4",
"resolved": "https://registry.npmjs.org/sass/-/sass-1.80.4.tgz",
"integrity": "sha512-rhMQ2tSF5CsuuspvC94nPM9rToiAFw2h3JTrLlgmNw1MH79v8Cr3DH6KF6o6r+8oofY3iYVPUf66KzC8yuVN1w==",
"license": "MIT",
"peer": true,
"dependencies": {
@ -12604,14 +12604,14 @@
}
},
"node_modules/vite-plugin-vue-devtools": {
"version": "7.5.3",
"resolved": "https://registry.npmjs.org/vite-plugin-vue-devtools/-/vite-plugin-vue-devtools-7.5.3.tgz",
"integrity": "sha512-gpR4S1anwc3rEapcealw0EATfQHO7jLCPqqT2qZAYLyVXsRi+Ysk7Z+kr/iq0sROfcVfSNAqAMB7foZobj2m5Q==",
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/vite-plugin-vue-devtools/-/vite-plugin-vue-devtools-7.5.4.tgz",
"integrity": "sha512-6yTcGrF+YdplDhNiNCkwj23BQDHA/jp06FR4Bo3rui1GW+8VdFcc26au2gtynPwRDNJXNueTxiVtVb6dq+lNZA==",
"license": "MIT",
"dependencies": {
"@vue/devtools-core": "^7.5.3",
"@vue/devtools-kit": "^7.5.3",
"@vue/devtools-shared": "^7.5.3",
"@vue/devtools-core": "^7.5.4",
"@vue/devtools-kit": "^7.5.4",
"@vue/devtools-shared": "^7.5.4",
"execa": "^8.0.1",
"sirv": "^3.0.0",
"vite-plugin-inspect": "^0.8.7",

View File

@ -26,7 +26,7 @@
"pinia": "^2.2.4",
"toastify-js": "^1.12.0",
"vite": "^5.4.10",
"vite-plugin-vue-devtools": "^7.5.3",
"vite-plugin-vue-devtools": "^7.5.4",
"vue": "^3.5.12",
"vue-material-design-icons": "^5.3.1",
"vue-router": "^4.4.5"

View File

@ -1,15 +1,15 @@
<template>
<NcGuestContent class="guest">
<Loading v-if="!metric.data" />
<Loading v-if="!feed.data" />
<NcAvatar
v-if="metric.data"
v-if="feed.data"
class="avatar"
:display-name="metric.data.author || metric.data.title"
:display-name="feed.data.author || feed.data.title"
:is-no-user="true"
:size="222"
:url="metric.data.imageUrl" />
<div v-if="metric.data" class="list">
<h2 class="title">{{ metric.data.title }}</h2>
:url="feed.data.imageUrl" />
<div v-if="feed.data" class="list">
<h2 class="title">{{ feed.data.title }}</h2>
<Loading v-if="loading" />
<ul v-if="!loading">
<Episode
@ -17,14 +17,14 @@
:key="episode.guid"
:episode="episode"
:one-line="true"
:url="metric.url" />
:url="feed.metrics.url" />
</ul>
</div>
</NcGuestContent>
</template>
<script lang="ts">
import type { EpisodeInterface, PodcastMetricsInterface } from '../../utils/types.ts'
import type { EpisodeInterface, SubscriptionInterface } from '../../utils/types.ts'
import { NcAvatar, NcGuestContent } from '@nextcloud/vue'
import Episode from './Episode.vue'
import Loading from '../Atoms/Loading.vue'
@ -43,8 +43,8 @@ export default {
NcGuestContent,
},
props: {
metric: {
type: Object as () => PodcastMetricsInterface,
feed: {
type: Object as () => SubscriptionInterface,
required: true,
},
},
@ -57,7 +57,7 @@ export default {
this.loading = true
const episodes = await axios.get<EpisodeInterface[]>(
generateUrl('/apps/repod/episodes/list?url={url}', {
url: this.metric.url,
url: this.feed.metrics.url,
}),
)
this.episodes = [...episodes.data]

View File

@ -1,18 +1,18 @@
<template>
<NcAppNavigationItem
:loading="loading"
:name="metric.data?.title || metric.url"
:to="toFeedUrl(metric.url)">
:name="feed?.data?.title || url"
:to="toFeedUrl(url)">
<template #actions>
<NcActionButton
:aria-label="t('repod', 'Favorite')"
:model-value="metric.isFavorite"
:model-value="feed?.isFavorite"
:name="t('repod', 'Favorite')"
:title="t('repod', 'Favorite')"
@update:modelValue="switchFavorite($event)">
<template #icon>
<StarPlusIcon v-if="!metric.isFavorite" :size="20" />
<StarRemoveIcon v-if="metric.isFavorite" :size="20" />
<StarPlusIcon v-if="!feed?.isFavorite" :size="20" />
<StarRemoveIcon v-if="feed?.isFavorite" :size="20" />
</template>
</NcActionButton>
<NcActionButton
@ -27,10 +27,11 @@
</template>
<template #icon>
<NcAvatar
:display-name="metric.data?.author || metric.data?.title"
:display-name="feed?.data?.author || feed?.data?.title"
:is-no-user="true"
:url="metric.data?.imageUrl" />
<StarIcon v-if="metric.isFavorite" class="star" :size="20" />
:url="feed?.data?.imageUrl" />
<StarIcon v-if="feed?.isFavorite" class="star" :size="20" />
<AlertIcon v-if="failed" />
</template>
</NcAppNavigationItem>
</template>
@ -38,8 +39,9 @@
<script lang="ts">
import { NcActionButton, NcAppNavigationItem, NcAvatar } from '@nextcloud/vue'
import { mapActions, mapState } from 'pinia'
import AlertIcon from 'vue-material-design-icons/Alert.vue'
import DeleteIcon from 'vue-material-design-icons/Delete.vue'
import type { PodcastMetricsInterface } from '../../utils/types.ts'
import type { PersonalSettingsPodcastDataInterface } from '../../utils/types.ts'
import StarIcon from 'vue-material-design-icons/Star.vue'
import StarPlusIcon from 'vue-material-design-icons/StarPlus.vue'
import StarRemoveIcon from 'vue-material-design-icons/StarRemove.vue'
@ -53,6 +55,7 @@ import { useSubscriptions } from '../../store/subscriptions.ts'
export default {
name: 'Subscription',
components: {
AlertIcon,
DeleteIcon,
NcActionButton,
NcAppNavigationItem,
@ -62,21 +65,44 @@ export default {
StarRemoveIcon,
},
props: {
metric: {
type: Object as () => PodcastMetricsInterface,
url: {
type: String,
required: true,
},
},
data() {
return {
loading: false,
failed: false,
loading: true,
}
},
computed: {
...mapState(useSubscriptions, ['getSubByUrl', 'subs']),
feed() {
return this.getSubByUrl(this.url)
},
},
async mounted() {
try {
const podcastData =
await axios.get<PersonalSettingsPodcastDataInterface>(
generateUrl(
'/apps/gpoddersync/personal_settings/podcast_data?url={url}',
{
url: this.url,
},
),
)
this.addMetadatas(this.url, podcastData.data.data)
} catch (e) {
this.failed = true
console.error(e)
} finally {
this.loading = false
}
},
methods: {
...mapActions(useSubscriptions, ['fetch', 'setFavorite']),
...mapActions(useSubscriptions, ['fetch', 'addMetadatas', 'setFavorite']),
t,
toFeedUrl,
async deleteSubscription() {
@ -89,14 +115,14 @@ export default {
this.loading = true
await axios.post(
generateUrl('/apps/gpoddersync/subscription_change/create'),
{ add: [], remove: [this.metric.url] },
{ add: [], remove: [this.url] },
)
} catch (e) {
console.error(e)
showError(t('repod', 'Error while removing the feed'))
} finally {
this.setFavorite(this.metric.url, false)
this.loading = true
this.setFavorite(this.url, false)
this.loading = false
this.fetch()
}
}
@ -108,7 +134,7 @@ export default {
return
}
}
this.setFavorite(this.metric.url, value)
this.setFavorite(this.url, value)
},
},
}

View File

@ -13,12 +13,12 @@
<NcAppNavigationList v-if="!loading">
<Subscription
v-for="sub of subs.filter((sub) => sub.isFavorite)"
:key="sub.url"
:metric="sub" />
:key="sub.metrics.url"
:url="sub.metrics.url" />
<Subscription
v-for="sub of subs.filter((sub) => !sub.isFavorite)"
:key="sub.url"
:metric="sub" />
:key="sub.metrics.url"
:url="sub.metrics.url" />
</NcAppNavigationList>
</NcAppContentList>
</template>

View File

@ -1,16 +1,20 @@
import type {
PersonalSettingsMetricsInterface,
PodcastDataInterface,
SubscriptionInterface,
} from '../utils/types.ts'
import { getCookie, setCookie } from '../utils/cookies.ts'
import type { PodcastMetricsInterface } from '../utils/types.ts'
import axios from '@nextcloud/axios'
import { defineStore } from 'pinia'
import { generateUrl } from '@nextcloud/router'
export const useSubscriptions = defineStore('subscriptions', {
state: () => ({
subs: [] as PodcastMetricsInterface[],
subs: [] as SubscriptionInterface[],
}),
getters: {
getSubByUrl: (state) => (url: string) =>
state.subs.find((sub) => sub.url === url),
state.subs.find((sub) => sub.metrics.url === url),
},
actions: {
async fetch() {
@ -19,24 +23,34 @@ export const useSubscriptions = defineStore('subscriptions', {
favorites = JSON.parse(getCookie('repod.favorites') || '[]') || []
} catch {}
const metrics = await axios.get<PodcastMetricsInterface[]>(
generateUrl('/apps/repod/metrics'),
const metrics = await axios.get<PersonalSettingsMetricsInterface>(
generateUrl('/apps/gpoddersync/personal_settings/metrics'),
)
this.subs = [...metrics.data].map((sub) => ({
...sub,
isFavorite: favorites.includes(sub.url),
}))
this.subs = [...metrics.data.subscriptions]
.sort((a, b) => b.listenedSeconds - a.listenedSeconds)
.map((sub) => ({
metrics: sub,
isFavorite: favorites.includes(sub.url),
data: this.getSubByUrl(sub.url)?.data,
}))
},
addMetadatas(link: string, data: PodcastDataInterface) {
this.subs = this.subs.map((sub) =>
sub.metrics.url === link ? { ...sub, data } : sub,
)
},
setFavorite(link: string, isFavorite: boolean) {
this.subs = this.subs.map((sub) =>
sub.url === link ? { ...sub, isFavorite } : sub,
sub.metrics.url === link ? { ...sub, isFavorite } : sub,
)
setCookie(
'repod.favorites',
JSON.stringify(
this.subs.filter((sub) => sub.isFavorite).map((sub) => sub.url),
this.subs
.filter((sub) => sub.isFavorite)
.map((sub) => sub.metrics.url),
),
365,
)

View File

@ -56,8 +56,16 @@ export interface PodcastMetricsInterface {
new: number
play: number
}
data: PodcastDataInterface
}
export interface SubscriptionInterface {
data?: PodcastDataInterface
isFavorite?: boolean
metrics: PodcastMetricsInterface
}
export interface PersonalSettingsMetricsInterface {
subscriptions: PodcastMetricsInterface[]
}
export interface PersonalSettingsPodcastDataInterface {

View File

@ -11,8 +11,8 @@
</template>
</EmptyContent>
<ul v-if="favorites.length">
<li v-for="favorite in favorites" :key="favorite.url">
<Favorite :metric="favorite" />
<li v-for="favorite in favorites" :key="favorite.metrics.url">
<Favorite :feed="favorite" />
</li>
</ul>
</AppContent>

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Nextcloud 3.14159\n"
"Report-Msgid-Bugs-To: translations\\@example.com\n"
"POT-Creation-Date: 2024-10-23 22:22+0000\n"
"POT-Creation-Date: 2024-10-24 21:38+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -219,6 +219,6 @@ msgstr ""
msgid "No favorites"
msgstr ""
#: /app/src/store/player.ts:82
#: /app/src/store/player.ts:89
msgid "A browser extension conflict with RePod"
msgstr ""