fix: channel cache fail-close, group conflict check across pages, status toggle stale data

- GetGroupPlatforms failure now stores error-TTL cache and returns error (fail-close)
- Frontend group-to-channel conflict map loads all channels instead of current page only
- Toggle channel status reloads list when active filter would hide the changed item
This commit is contained in:
erio
2026-04-02 23:47:37 +08:00
parent 71f61bbc47
commit feb6999d9a
4 changed files with 35 additions and 11 deletions

View File

@@ -499,6 +499,9 @@ const activeTab = ref<string>('basic')
const allGroups = ref<AdminGroup[]>([])
const groupsLoading = ref(false)
// All channels for group-conflict detection (independent of current page)
const allChannelsForConflict = ref<Channel[]>([])
// Form data
const form = reactive({
name: '',
@@ -575,7 +578,7 @@ function getGroupsForPlatform(platform: GroupPlatform): AdminGroup[] {
// ── Group helpers ──
const groupToChannelMap = computed(() => {
const map = new Map<number, Channel>()
for (const ch of channels.value) {
for (const ch of allChannelsForConflict.value) {
if (editingChannel.value && ch.id === editingChannel.value.id) continue
for (const gid of ch.group_ids || []) {
map.set(gid, ch)
@@ -794,6 +797,16 @@ async function loadGroups() {
}
}
async function loadAllChannelsForConflict() {
try {
const response = await adminAPI.channels.list(1, 1000)
allChannelsForConflict.value = response.items || []
} catch (error) {
// Fallback to current page data
allChannelsForConflict.value = channels.value
}
}
let searchTimeout: ReturnType<typeof setTimeout>
function handleSearch() {
clearTimeout(searchTimeout)
@@ -828,7 +841,7 @@ function resetForm() {
async function openCreateDialog() {
editingChannel.value = null
resetForm()
await loadGroups()
await Promise.all([loadGroups(), loadAllChannelsForConflict()])
showDialog.value = true
}
@@ -840,7 +853,7 @@ async function openEditDialog(channel: Channel) {
form.restrict_models = channel.restrict_models || false
form.billing_model_source = channel.billing_model_source || 'channel_mapped'
// Must load groups first so apiToForm can map groupID → platform
await loadGroups()
await Promise.all([loadGroups(), loadAllChannelsForConflict()])
form.platforms = apiToForm(channel)
showDialog.value = true
}
@@ -985,7 +998,12 @@ async function toggleChannelStatus(channel: Channel) {
const newStatus = channel.status === 'active' ? 'disabled' : 'active'
try {
await adminAPI.channels.update(channel.id, { status: newStatus })
channel.status = newStatus
if (filters.status && filters.status !== newStatus) {
// Item no longer matches the active filter — reload list
await loadChannels()
} else {
channel.status = newStatus
}
} catch (error) {
appStore.showError(t('admin.channels.updateError', 'Failed to update channel'))
console.error('Error toggling channel status:', error)