Skip to content

Commit 4871abf

Browse files
authored
fix: worker exceeding resources bug caused by large changelogs (#5121)
* fetch changelog only where actually used * use query parameter properly * remove todos * pnpm prepr
1 parent b0ed808 commit 4871abf

File tree

3 files changed

+82
-47
lines changed

3 files changed

+82
-47
lines changed

apps/frontend/src/pages/[type]/[id].vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,10 +1533,19 @@ try {
15331533
useBaseFetch(`project/${projectId.value}/dependencies`, {}),
15341534
),
15351535
useAsyncData(`project/${projectId.value}/version`, () =>
1536-
useBaseFetch(`project/${projectId.value}/version`),
1536+
useBaseFetch(`project/${projectId.value}/version`, {
1537+
query: {
1538+
include_changelog: false,
1539+
},
1540+
}),
15371541
),
15381542
useAsyncData(`project/${projectId.value}/version/v3`, () =>
1539-
useBaseFetch(`project/${projectId.value}/version`, { apiVersion: 3 }),
1543+
useBaseFetch(`project/${projectId.value}/version`, {
1544+
apiVersion: 3,
1545+
query: {
1546+
include_changelog: false,
1547+
},
1548+
}),
15401549
),
15411550
useAsyncData(`project/${projectId.value}/organization`, () =>
15421551
useBaseFetch(`project/${projectId.value}/organization`, { apiVersion: 3 }),

apps/frontend/src/pages/[type]/[id]/changelog.vue

Lines changed: 67 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,53 +15,54 @@
1515
/>
1616
</div>
1717
<div class="card changelog-wrapper">
18-
<div
19-
v-for="version in filteredVersions.slice((currentPage - 1) * 20, currentPage * 20)"
20-
:key="version.id"
21-
class="changelog-item"
22-
>
23-
<div
24-
:class="`changelog-bar ${version.version_type} ${version.duplicate ? 'duplicate' : ''}`"
25-
/>
26-
<div class="version-wrapper">
27-
<div class="version-header">
28-
<div class="version-header-text">
29-
<h2 class="name">
30-
<nuxt-link
31-
:to="`/${props.project.project_type}/${
32-
props.project.slug ? props.project.slug : props.project.id
33-
}/version/${encodeURI(version.displayUrlEnding)}`"
18+
<template v-if="paginatedVersions">
19+
<div v-for="version in paginatedVersions" :key="version.id" class="changelog-item">
20+
<div
21+
:class="`changelog-bar ${version.version_type} ${version.duplicate ? 'duplicate' : ''}`"
22+
/>
23+
<div class="version-wrapper">
24+
<div class="version-header">
25+
<div class="version-header-text">
26+
<h2 class="name">
27+
<nuxt-link
28+
:to="`/${props.project.project_type}/${
29+
props.project.slug ? props.project.slug : props.project.id
30+
}/version/${encodeURI(version.displayUrlEnding)}`"
31+
>
32+
{{ version.name }}
33+
</nuxt-link>
34+
</h2>
35+
<span v-if="version.author">
36+
by
37+
<nuxt-link class="text-link" :to="'/user/' + version.author.user.username">{{
38+
version.author.user.username
39+
}}</nuxt-link>
40+
</span>
41+
<span>
42+
on
43+
{{ $dayjs(version.date_published).format('MMM D, YYYY') }}</span
3444
>
35-
{{ version.name }}
36-
</nuxt-link>
37-
</h2>
38-
<span v-if="version.author">
39-
by
40-
<nuxt-link class="text-link" :to="'/user/' + version.author.user.username">{{
41-
version.author.user.username
42-
}}</nuxt-link>
43-
</span>
44-
<span>
45-
on
46-
{{ $dayjs(version.date_published).format('MMM D, YYYY') }}</span
45+
</div>
46+
<a
47+
:href="version.primaryFile?.url"
48+
class="iconified-button download"
49+
:title="`Download ${version.name}`"
4750
>
51+
<DownloadIcon aria-hidden="true" />
52+
Download
53+
</a>
4854
</div>
49-
<a
50-
:href="version.primaryFile?.url"
51-
class="iconified-button download"
52-
:title="`Download ${version.name}`"
53-
>
54-
<DownloadIcon aria-hidden="true" />
55-
Download
56-
</a>
55+
<div
56+
v-if="version.changelog && !version.duplicate"
57+
class="markdown-body"
58+
v-html="renderHighlightedString(version.changelog)"
59+
/>
5760
</div>
58-
<div
59-
v-if="version.changelog && !version.duplicate"
60-
class="markdown-body"
61-
v-html="renderHighlightedString(version.changelog)"
62-
/>
6361
</div>
64-
</div>
62+
</template>
63+
<template v-else>
64+
<SpinnerIcon class="animate-spin" />
65+
</template>
6566
</div>
6667
<Pagination
6768
:page="currentPage"
@@ -73,8 +74,8 @@
7374
</div>
7475
</template>
7576
<script setup>
76-
import { DownloadIcon } from '@modrinth/assets'
77-
import { Pagination } from '@modrinth/ui'
77+
import { DownloadIcon, SpinnerIcon } from '@modrinth/assets'
78+
import { injectModrinthClient, Pagination } from '@modrinth/ui'
7879
import VersionFilterControl from '@modrinth/ui/src/components/version/VersionFilterControl.vue'
7980
import { renderHighlightedString } from '@modrinth/utils'
8081
@@ -132,6 +133,28 @@ const filteredVersions = computed(() => {
132133
)
133134
})
134135
136+
const { labrinth } = injectModrinthClient()
137+
138+
const paginatedVersions = ref(null)
139+
140+
watch(
141+
[filteredVersions, currentPage],
142+
async ([filtered, page]) => {
143+
const paginated = filtered.slice((page - 1) * 20, page * 20)
144+
145+
const ids = paginated.map((v) => v.id)
146+
const versions = await labrinth.versions_v3.getVersions(toRaw(ids))
147+
148+
paginatedVersions.value = paginated.map((version) => {
149+
const fullVersion = versions.find((v) => v.id === version.id)
150+
151+
if (fullVersion) return { ...version, changelog: fullVersion.changelog }
152+
else return version
153+
})
154+
},
155+
{ immediate: true },
156+
)
157+
135158
function switchPage(page) {
136159
currentPage.value = page
137160

apps/frontend/src/pages/[type]/[id]/version/[version].vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,10 @@ export default defineNuxtComponent({
861861
`project/${props.project.id}/version/${route.params.version}`,
862862
{ apiVersion: 3 },
863863
)
864-
if (versionV3) version.environment = versionV3.environment
864+
if (versionV3) {
865+
version.environment = versionV3.environment
866+
version.changelog = versionV3.changelog
867+
}
865868
}
866869
867870
if (!version) {

0 commit comments

Comments
 (0)