传递关键词缓存信息
This commit is contained in:
Vendored
-2
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Vendored
+2
File diff suppressed because one or more lines are too long
Vendored
+2
-2
@@ -5,8 +5,8 @@
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>SESE 爬取管理</title>
|
||||
<script type="module" crossorigin src="/assets/index-CxvnbVf9.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-BlMKGOqe.css">
|
||||
<script type="module" crossorigin src="/assets/index-CYFclJJJ.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-D1EwdjSH.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
||||
@@ -98,6 +98,13 @@ func (c *urlKeywordsCache) Get(url string) ([]urlKeywordInfo, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// Stats 返回缓存统计信息
|
||||
func (c *urlKeywordsCache) Stats() (size int, maxSize int) {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
return len(c.items), c.maxSize
|
||||
}
|
||||
|
||||
// Server 是搜索 HTTP 服务器,同时内嵌收获服务(统一在同一端口)。
|
||||
type Server struct {
|
||||
db *storage.DB
|
||||
@@ -209,6 +216,7 @@ func (s *Server) Handler() http.Handler {
|
||||
mux.HandleFunc("/admin/backlink", s.handleAdminBacklink)
|
||||
mux.HandleFunc("/admin/crawl/status", s.handleAdminCrawlStatus)
|
||||
mux.HandleFunc("/admin/url/keywords", s.handleUrlKeywords)
|
||||
mux.HandleFunc("/admin/url/keywords/stats", s.handleUrlKeywordsStats)
|
||||
// 静态文件(SPA fallback)
|
||||
mux.Handle("/", spaHandler{dist: "dist"})
|
||||
return mux
|
||||
@@ -847,6 +855,34 @@ func (s *Server) handleUrlKeywords(w http.ResponseWriter, r *http.Request) {
|
||||
json.NewEncoder(w).Encode(resp)
|
||||
}
|
||||
|
||||
// handleUrlKeywordsStats 返回 URL 关键词缓存的统计信息
|
||||
func (s *Server) handleUrlKeywordsStats(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
|
||||
if r.Method != http.MethodGet && r.Method != http.MethodOptions {
|
||||
http.Error(w, `{"error":"method not allowed"}`, http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
if r.Method == http.MethodOptions {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
size, maxSize := s.urlKeywords.Stats()
|
||||
resp := struct {
|
||||
Size int `json:"size"` // 当前缓存的 URL 数量
|
||||
MaxSize int `json:"max_size"` // 缓存容量上限
|
||||
Usage float64 `json:"usage"` // 使用率 (0-1)
|
||||
}{
|
||||
Size: size,
|
||||
MaxSize: maxSize,
|
||||
Usage: float64(size) / float64(maxSize),
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(resp)
|
||||
}
|
||||
|
||||
// ---- 搜索处理器 ----
|
||||
|
||||
// searchResponse 是搜索 API 的 JSON 响应结构。
|
||||
|
||||
+1
-1
Submodule sese-engine-ui updated: 422033fc6d...5c944b7c90
Reference in New Issue
Block a user