优化刷盘轮询,修复优先队列数量错误
This commit is contained in:
+3
-1
@@ -246,12 +246,14 @@ func (c *Crawler) runPriorityWorker() {
|
|||||||
// 将子链接加入优先队列(保持优先级)
|
// 将子链接加入优先队列(保持优先级)
|
||||||
if len(hrefs) > 0 {
|
if len(hrefs) > 0 {
|
||||||
c.priorityChildrenMu.Lock()
|
c.priorityChildrenMu.Lock()
|
||||||
|
added := 0
|
||||||
for _, child := range hrefs {
|
for _, child := range hrefs {
|
||||||
if !c.isVisited(child) {
|
if !c.isVisited(child) {
|
||||||
c.priorityChildren = append(c.priorityChildren, child)
|
c.priorityChildren = append(c.priorityChildren, child)
|
||||||
|
added++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IncrementPriorityChildren(int64(len(hrefs)))
|
IncrementPriorityChildren(int64(added))
|
||||||
c.priorityChildrenMu.Unlock()
|
c.priorityChildrenMu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
-6
File diff suppressed because one or more lines are too long
Vendored
+6
File diff suppressed because one or more lines are too long
Vendored
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>SESE 爬取管理</title>
|
<title>SESE 爬取管理</title>
|
||||||
<script type="module" crossorigin src="/assets/index-CiQvUT0P.js"></script>
|
<script type="module" crossorigin src="/assets/index-UuqaCCT8.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-Dr22_wUg.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-Dr22_wUg.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ func (s *Server) Handler() http.Handler {
|
|||||||
mux.HandleFunc("/admin/priority", s.handleAdminPriority)
|
mux.HandleFunc("/admin/priority", s.handleAdminPriority)
|
||||||
mux.HandleFunc("/admin/priority/status", s.handleAdminPriorityStatus)
|
mux.HandleFunc("/admin/priority/status", s.handleAdminPriorityStatus)
|
||||||
mux.HandleFunc("/admin/flush", s.handleAdminFlush)
|
mux.HandleFunc("/admin/flush", s.handleAdminFlush)
|
||||||
|
mux.HandleFunc("/admin/flush/status", s.handleAdminFlushStatus)
|
||||||
mux.HandleFunc("/admin/pending", s.handleAdminPending)
|
mux.HandleFunc("/admin/pending", s.handleAdminPending)
|
||||||
mux.HandleFunc("/admin/workers", s.handleAdminWorkers)
|
mux.HandleFunc("/admin/workers", s.handleAdminWorkers)
|
||||||
mux.HandleFunc("/admin/backlink", s.handleAdminBacklink)
|
mux.HandleFunc("/admin/backlink", s.handleAdminBacklink)
|
||||||
@@ -592,6 +593,29 @@ func (s *Server) handleAdminFlush(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Write([]byte("flushed"))
|
w.Write([]byte("flushed"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handleAdminFlushStatus 返回当前是否正在刷盘。
|
||||||
|
// GET: 返回 flushing (bool)
|
||||||
|
func (s *Server) handleAdminFlushStatus(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"}`, 405)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if r.Method == http.MethodOptions {
|
||||||
|
w.WriteHeader(204)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// flushMu.TryLock() 返回 false 表示锁被占用(正在刷盘)
|
||||||
|
flushing := !s.flushMu.TryLock()
|
||||||
|
if flushing {
|
||||||
|
json.NewEncoder(w).Encode(map[string]bool{"flushing": true})
|
||||||
|
} else {
|
||||||
|
s.flushMu.Unlock()
|
||||||
|
json.NewEncoder(w).Encode(map[string]bool{"flushing": false})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// handleAdminPending 返回内存中未刷盘的索引条目数量。
|
// handleAdminPending 返回内存中未刷盘的索引条目数量。
|
||||||
func (s *Server) handleAdminPending(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleAdminPending(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
|||||||
+1
-1
Submodule sese-engine-ui updated: e256b65f10...01dcc396f5
Reference in New Issue
Block a user