fix: refresh wiki status after document polling completes
This commit is contained in:
@@ -42,6 +42,11 @@ import DocumentListView from './components/DocumentListView.vue';
|
|||||||
import DocumentBatchBar from './components/DocumentBatchBar.vue';
|
import DocumentBatchBar from './components/DocumentBatchBar.vue';
|
||||||
import WikiBrowser from './wiki/WikiBrowser.vue';
|
import WikiBrowser from './wiki/WikiBrowser.vue';
|
||||||
import { getWikiStats } from '@/api/wiki';
|
import { getWikiStats } from '@/api/wiki';
|
||||||
|
import {
|
||||||
|
isKnowledgeParseInFlight,
|
||||||
|
knowledgeNeedsStatusPolling,
|
||||||
|
shouldRefreshWikiStatusAfterKnowledgePoll,
|
||||||
|
} from './wikiStatusRefresh';
|
||||||
import { listMoveTargets, moveKnowledge, getKnowledgeMoveProgress } from '@/api/knowledge-base';
|
import { listMoveTargets, moveKnowledge, getKnowledgeMoveProgress } from '@/api/knowledge-base';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { formatStringDate, kbFileTypeVerification } from '@/utils';
|
import { formatStringDate, kbFileTypeVerification } from '@/utils';
|
||||||
@@ -320,7 +325,7 @@ function clearTraceAvailabilityCache() {
|
|||||||
// (primary parse OR post-process fan-out). Trace data exists and the
|
// (primary parse OR post-process fan-out). Trace data exists and the
|
||||||
// UI should treat the row as "in flight" rather than terminal.
|
// UI should treat the row as "in flight" rather than terminal.
|
||||||
function isParseInFlight(status?: string): boolean {
|
function isParseInFlight(status?: string): boolean {
|
||||||
return status === 'pending' || status === 'processing' || status === 'finalizing';
|
return isKnowledgeParseInFlight(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status line shown on the card body while parse is still in flight.
|
// Status line shown on the card body while parse is still in flight.
|
||||||
@@ -1091,9 +1096,7 @@ type KnowledgeCard = {
|
|||||||
// graph extract still running), and a `completed` row whose summary
|
// graph extract still running), and a `completed` row whose summary
|
||||||
// hasn't landed yet keeps polling so the description fills in.
|
// hasn't landed yet keeps polling so the description fills in.
|
||||||
const needsStatusPolling = (item: KnowledgeCard) => {
|
const needsStatusPolling = (item: KnowledgeCard) => {
|
||||||
if (isParseInFlight(item.parse_status)) return true;
|
return knowledgeNeedsStatusPolling(item);
|
||||||
return item.parse_status == 'completed' &&
|
|
||||||
(item.summary_status == 'pending' || item.summary_status == 'processing');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateStatus = (analyzeList: KnowledgeCard[]) => {
|
const updateStatus = (analyzeList: KnowledgeCard[]) => {
|
||||||
@@ -1110,6 +1113,7 @@ const updateStatus = (analyzeList: KnowledgeCard[]) => {
|
|||||||
timeout = setTimeout(() => {
|
timeout = setTimeout(() => {
|
||||||
batchQueryKnowledge(query).then((result: any) => {
|
batchQueryKnowledge(query).then((result: any) => {
|
||||||
let hasChanges = false;
|
let hasChanges = false;
|
||||||
|
let shouldRefreshWikiStatus = false;
|
||||||
if (result.success && result.data) {
|
if (result.success && result.data) {
|
||||||
(result.data as KnowledgeCard[]).forEach((item: KnowledgeCard) => {
|
(result.data as KnowledgeCard[]).forEach((item: KnowledgeCard) => {
|
||||||
const index = cardList.value.findIndex(card => card.id == item.id);
|
const index = cardList.value.findIndex(card => card.id == item.id);
|
||||||
@@ -1118,6 +1122,7 @@ const updateStatus = (analyzeList: KnowledgeCard[]) => {
|
|||||||
if (cardList.value[index].parse_status !== item.parse_status ||
|
if (cardList.value[index].parse_status !== item.parse_status ||
|
||||||
cardList.value[index].summary_status !== item.summary_status ||
|
cardList.value[index].summary_status !== item.summary_status ||
|
||||||
cardList.value[index].description !== item.description) {
|
cardList.value[index].description !== item.description) {
|
||||||
|
shouldRefreshWikiStatus ||= shouldRefreshWikiStatusAfterKnowledgePoll(cardList.value[index], item);
|
||||||
|
|
||||||
// Always update the card data
|
// Always update the card data
|
||||||
cardList.value[index].parse_status = item.parse_status;
|
cardList.value[index].parse_status = item.parse_status;
|
||||||
@@ -1128,6 +1133,9 @@ const updateStatus = (analyzeList: KnowledgeCard[]) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (shouldRefreshWikiStatus) {
|
||||||
|
void fetchWikiStatusOnce();
|
||||||
|
}
|
||||||
// If there are no changes, the watch won't trigger, so we must manually poll again
|
// If there are no changes, the watch won't trigger, so we must manually poll again
|
||||||
// Even if there are changes, we can manually poll again just to be safe.
|
// Even if there are changes, we can manually poll again just to be safe.
|
||||||
// The watch will clear this timeout if it triggers.
|
// The watch will clear this timeout if it triggers.
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import test from 'node:test'
|
||||||
|
|
||||||
|
import { shouldRefreshWikiStatusAfterKnowledgePoll } from './wikiStatusRefresh.ts'
|
||||||
|
|
||||||
|
test('refreshes wiki status when a polled document leaves an in-flight state', () => {
|
||||||
|
assert.equal(
|
||||||
|
shouldRefreshWikiStatusAfterKnowledgePoll(
|
||||||
|
{ parse_status: 'finalizing', summary_status: 'processing' },
|
||||||
|
{ parse_status: 'completed', summary_status: 'completed' },
|
||||||
|
),
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('does not refresh wiki status for ordinary in-flight polling updates', () => {
|
||||||
|
assert.equal(
|
||||||
|
shouldRefreshWikiStatusAfterKnowledgePoll(
|
||||||
|
{ parse_status: 'pending' },
|
||||||
|
{ parse_status: 'processing' },
|
||||||
|
),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
})
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
export type KnowledgePollStatus = {
|
||||||
|
parse_status?: string
|
||||||
|
summary_status?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isKnowledgeParseInFlight(status?: string): boolean {
|
||||||
|
return status === 'pending' || status === 'processing' || status === 'finalizing'
|
||||||
|
}
|
||||||
|
|
||||||
|
export function knowledgeNeedsStatusPolling(item: KnowledgePollStatus): boolean {
|
||||||
|
if (isKnowledgeParseInFlight(item.parse_status)) return true
|
||||||
|
return item.parse_status === 'completed' &&
|
||||||
|
(item.summary_status === 'pending' || item.summary_status === 'processing')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function shouldRefreshWikiStatusAfterKnowledgePoll(
|
||||||
|
before: KnowledgePollStatus,
|
||||||
|
after: KnowledgePollStatus,
|
||||||
|
): boolean {
|
||||||
|
return knowledgeNeedsStatusPolling(before) && !knowledgeNeedsStatusPolling(after)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user