feat: Add pending tasks and active status to WikiStats

- Introduced `pending_tasks` and `is_active` fields in the `WikiStats` interface to track the number of tasks waiting for processing and the current activity status of the wiki ingestion.
- Updated localization files for English, Korean, Russian, and Chinese to include a new message for displaying the number of pending tasks in the wiki queue.
- Enhanced the `WikiBrowser` component to display the queue status, improving user awareness of ongoing tasks.
- Implemented polling logic to refresh wiki stats periodically when there are pending tasks or active ingestion, ensuring up-to-date information is presented.

These changes enhance the functionality and user experience of the wiki management system by providing real-time insights into task status.
This commit is contained in:
wizardchen
2026-04-09 13:35:46 +08:00
parent a81ef5fbb2
commit 8daf6b368c
17 changed files with 682 additions and 229 deletions
+20 -6
View File
@@ -13,6 +13,7 @@ import (
"github.com/Tencent/WeKnora/internal/types"
"github.com/Tencent/WeKnora/internal/types/interfaces"
"github.com/google/uuid"
"github.com/redis/go-redis/v9"
)
// wikiLinkRegex matches [[wiki-link]] syntax in markdown content
@@ -20,9 +21,10 @@ var wikiLinkRegex = regexp.MustCompile(`\[\[([^\]]+)\]\]`)
// wikiPageService implements the WikiPageService interface
type wikiPageService struct {
repo interfaces.WikiPageRepository
chunkRepo interfaces.ChunkRepository
kbService interfaces.KnowledgeBaseService
repo interfaces.WikiPageRepository
chunkRepo interfaces.ChunkRepository
kbService interfaces.KnowledgeBaseService
redisClient *redis.Client
}
// NewWikiPageService creates a new wiki page service
@@ -30,11 +32,13 @@ func NewWikiPageService(
repo interfaces.WikiPageRepository,
chunkRepo interfaces.ChunkRepository,
kbService interfaces.KnowledgeBaseService,
redisClient *redis.Client,
) interfaces.WikiPageService {
return &wikiPageService{
repo: repo,
chunkRepo: chunkRepo,
kbService: kbService,
repo: repo,
chunkRepo: chunkRepo,
kbService: kbService,
redisClient: redisClient,
}
}
@@ -283,12 +287,22 @@ func (s *wikiPageService) GetStats(ctx context.Context, kbID string) (*types.Wik
return nil, err
}
var pendingTasks int64
var isActive bool
if s.redisClient != nil {
pendingTasks, _ = s.redisClient.LLen(ctx, "wiki:pending:"+kbID).Result()
activeFlag, _ := s.redisClient.Exists(ctx, "wiki:active:"+kbID).Result()
isActive = activeFlag > 0
}
return &types.WikiStats{
TotalPages: total,
PagesByType: counts,
TotalLinks: totalLinks,
OrphanCount: orphans,
RecentUpdates: recentPages,
PendingTasks: pendingTasks,
IsActive: isActive,
}, nil
}