Implement CSV fetching utility with retry logic in Mannschaften component
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 50s
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 50s
This commit introduces a new utility function, fetchCsvText, to enhance the fetching of CSV data in the Mannschaften component. The function includes a cache-busting mechanism and retry logic to improve reliability when retrieving data from the server. Additionally, it updates the loadMannschaften function to utilize this new utility, ensuring better error handling and consistent data retrieval. These changes contribute to a more robust application.
This commit is contained in:
@@ -463,6 +463,25 @@ function serializeSpielerNames(spielerNames) {
|
|||||||
.join('; ')
|
.join('; ')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchCsvText(url) {
|
||||||
|
const attempt = async () => {
|
||||||
|
const withBuster = `${url}${url.includes('?') ? '&' : '?'}_t=${Date.now()}`
|
||||||
|
const response = await fetch(withBuster, { cache: 'no-store' })
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`)
|
||||||
|
}
|
||||||
|
return await response.text()
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await attempt()
|
||||||
|
} catch (e) {
|
||||||
|
// 1 Retry: hilft bei Firefox NS_ERROR_NET_PARTIAL_TRANSFER direkt nach Speichern
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 150))
|
||||||
|
return await attempt()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const mannschaftenSelectOptions = computed(() => {
|
const mannschaftenSelectOptions = computed(() => {
|
||||||
const current = (formData.value.mannschaft || '').trim()
|
const current = (formData.value.mannschaft || '').trim()
|
||||||
const names = mannschaften.value
|
const names = mannschaften.value
|
||||||
@@ -489,14 +508,7 @@ function getPendingSpielerNamesForTeamIndex(teamIndex) {
|
|||||||
const loadMannschaften = async () => {
|
const loadMannschaften = async () => {
|
||||||
isLoading.value = true
|
isLoading.value = true
|
||||||
try {
|
try {
|
||||||
// Cache-Buster: Browser/CDN könnten CSV sonst aggressiv cachen
|
const csv = await fetchCsvText('/data/mannschaften.csv')
|
||||||
const url = `/data/mannschaften.csv?_t=${Date.now()}`
|
|
||||||
const response = await fetch(url, { cache: 'no-store' })
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Fehler beim Laden der Mannschaften')
|
|
||||||
}
|
|
||||||
|
|
||||||
const csv = await response.text()
|
|
||||||
const lines = csv.split('\n').filter(line => line.trim() !== '')
|
const lines = csv.split('\n').filter(line => line.trim() !== '')
|
||||||
|
|
||||||
if (lines.length < 2) {
|
if (lines.length < 2) {
|
||||||
@@ -542,6 +554,7 @@ const loadMannschaften = async () => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Fehler beim Laden der Mannschaften:', error)
|
console.error('Fehler beim Laden der Mannschaften:', error)
|
||||||
errorMessage.value = 'Fehler beim Laden der Mannschaften'
|
errorMessage.value = 'Fehler beim Laden der Mannschaften'
|
||||||
|
throw error
|
||||||
} finally {
|
} finally {
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
}
|
}
|
||||||
@@ -809,7 +822,7 @@ const confirmDelete = (mannschaft, index) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadMannschaften()
|
loadMannschaften().catch(() => {})
|
||||||
})
|
})
|
||||||
|
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
|
|||||||
Reference in New Issue
Block a user