mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-18 22:36:10 +01:00
🎨 Distinguishing between a referenced definition block that does not exist or one that is not indexed https://github.com/siyuan-note/siyuan/issues/16850
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
ddf35ec7df
commit
05380060fc
18 changed files with 166 additions and 56 deletions
|
|
@ -1644,7 +1644,7 @@
|
|||
"194": "<a href=\"https://help.jianguoyun.com/?p=2064\" target=\"_blank\">هناك قيود على واجهة Nutstore</a>، يرجى استخدام خدمات WebDAV الأخرى",
|
||||
"195": "وقت النظام غير صحيح، يرجى معايرة وقت النظام والمحاولة مرة أخرى",
|
||||
"196": "لا تقم بتعيين مساحة العمل تحت مسار قرص مزامنة من طرف ثالث، وإلا فإن البيانات سوف تتلف (iCloud/OneDrive/ropbox/Google Drive/Nutstore/Baidu Netdisk/Tencent Weiyun، إلخ)",
|
||||
"197": "",
|
||||
"197": "يرجى فتح المفكرة [%s] ثم المحاولة مرة أخرى",
|
||||
"198": "هذا ليس أرشيف بيانات صالح. إذا تم تصدير الأرشيف من [شجرة المستندات]، الرجاء استيراده من [شجرة المستندات]",
|
||||
"199": "هذا ليس أرشيف .sy.zip الصالح. إذا تم تصدير الأرشيف من [الإعدادات]، الرجاء استيراده من [الإعدادات]",
|
||||
"200": "وقت استجابة البحث العالمي بطيء ، يوصى بإضافة فلتر النوع أو الكلمات الرئيسية لتضييق نطاق البحث",
|
||||
|
|
|
|||
|
|
@ -1644,7 +1644,7 @@
|
|||
"194": "<a href=\"https://help.jianguoyun.com/?p=2064\" target=\"_blank\">Es gibt Einschränkungen auf der Nutstore-Schnittstelle</a>, bitte verwenden Sie andere WebDAV-Dienste",
|
||||
"195": "Die Systemzeit ist falsch, bitte kalibrieren Sie die Systemzeit und versuchen Sie es erneut",
|
||||
"196": "Setzen Sie das Arbeitsbereich nicht unter dem Pfad eines Drittanbieter-Synchronisationslaufwerks, da sonst die Daten beschädigt werden (iCloud/OneDrive/Dropbox/Google Drive/Nutstore/Baidu Netdisk/Tencent Weiyun usw.)",
|
||||
"197": "",
|
||||
"197": "Bitte öffnen Sie das Notizbuch [%s] und versuchen Sie es erneut",
|
||||
"198": "Dies ist kein gültiges Datenarchiv. Wenn das Archiv aus [Dokumentenbaum] exportiert wurde, importieren Sie es bitte aus [Dokumentenbaum]",
|
||||
"199": "Dies ist kein gültiges .sy.zip Archiv. Wenn das Archiv aus [Einstellungen] exportiert wurde, importieren Sie es bitte aus [Einstellungen]",
|
||||
"200": "Die Reaktionszeit der globalen Suche ist langsam, es wird empfohlen, Typfilter oder Schlüsselwörter hinzuzufügen, um den Suchbereich einzugrenzen",
|
||||
|
|
|
|||
|
|
@ -1644,7 +1644,7 @@
|
|||
"194": "<a href=\"https://help.jianguoyun.com/?p=2064\" target=\"_blank\">There are restrictions on the Nutstore interface</a>, please use other WebDAV services",
|
||||
"195": "The system time is incorrect, please calibrate the system time and try again",
|
||||
"196": "Do not set the workspace under the path of a third-party sync disk, otherwise the data will be damaged (iCloud/OneDrive/Dropbox/Google Drive/Nutstore/Baidu Netdisk/Tencent Weiyun, etc.)",
|
||||
"197": "",
|
||||
"197": "Please open notebook [%s] and try again",
|
||||
"198": "This is not a valid Data archive. If the archive was exported from [Doc tree], please import it from [Doc tree]",
|
||||
"199": "This is not a valid .sy.zip archive. If the archive was exported from [Settings], please import it from [Settings]",
|
||||
"200": "Global search response time is slow, it is recommended to add type filtering or keywords to narrow the search scope",
|
||||
|
|
|
|||
|
|
@ -1644,7 +1644,7 @@
|
|||
"194": "<a href=\"https://help.jianguoyun.com/?p=2064\" target=\"_blank\">Existen restricciones en la interfaz de Nutstore</a>, utilice otros servicios WebDAV",
|
||||
"195": "La hora del sistema es incorrecta, calibre la hora del sistema y vuelva a intentarlo",
|
||||
"196": "No configure el espacio de trabajo bajo la ruta de un disco de sincronización de terceros, de lo contrario, los datos se dañarán (iCloud/OneDrive/Dropbox/Google Drive/Nutstore/Baidu Netdisk/Tencent Weiyun, etc.)",
|
||||
"197": "",
|
||||
"197": "Por favor, abra el cuaderno [%s] y vuelva a intentarlo",
|
||||
"198": "Este no es un archivo data.zip válido. Si el archivo se exportó de [Documentos], importalo de [Documentos]",
|
||||
"199": "Este no es un archivo .sy.zip válido. Si el archivo se exportó desde [Configuración], impórtelo desde [Configuración]",
|
||||
"200": "El tiempo de respuesta de b\u00fasqueda global es lento, se recomienda agregar filtros de tipo o palabras clave para reducir el alcance de b\u00fasqueda",
|
||||
|
|
|
|||
|
|
@ -1644,7 +1644,7 @@
|
|||
"194": "<a href=\"https://help.jianguoyun.com/?p=2064\" target=\"_blank\">Il existe des restrictions sur l'interface Nutstore</a>, veuillez utiliser d'autres services WebDAV",
|
||||
"195": "L'heure du système est incorrecte, veuillez calibrer l'heure du système et réessayer",
|
||||
"196": "Ne définissez pas l'espace de travail sous le chemin d'un disque de synchronisation tiers, sinon les données seront endommagées (iCloud/OneDrive/Dropbox/Google Drive/Nutstore/Baidu Netdisk/Tencent Weiyun, etc.)",
|
||||
"197": "",
|
||||
"197": "Veuillez ouvrir le carnet [%s] puis réessayez",
|
||||
"198": "Ceci n'est pas une archive data.zip valide. Si l'archive a été exportée depuis [Doc tree], veuillez l'importer depuis [Doc tree]",
|
||||
"199": "Ceci n'est pas une archive .sy.zip valide. Si l'archive a été exportée depuis [Paramètres], veuillez l'importer depuis [Paramètres]",
|
||||
"200": "Le temps de réponse de la recherche globale est lent, il est recommandé d'ajouter un filtrage de type ou des mots-clés pour restreindre la portée de la recherche",
|
||||
|
|
|
|||
|
|
@ -1644,7 +1644,7 @@
|
|||
"194": "<a href=\"https://help.jianguoyun.com/?p=2064\" target=\"_blank\">יש הגבלות על ממשק Nutstore</a>, אנא השתמש בשירותי WebDAV אחרים",
|
||||
"195": "שעת המערכת שגויה, אנא כיול את שעת המערכת ונסה שוב",
|
||||
"196": "אל תקבע את חלל העבודה תחת נתיב דיסק סנכרון צד שלישי, אחרת הנתונים יפגמו (iCloud/OneDrive/Dropbox/Google Drive/Nutstore/Baidu Netdisk/Tencent Weiyun וכו')",
|
||||
"197": "",
|
||||
"197": "אנא פתח את המחברת [%s] ונסה שוב",
|
||||
"198": "זה אינו מאגר נתונים תקף. אם המאגר ייצא מ[עץ המסמכים], אנא ייבא אותו מ[עץ המסמכים]",
|
||||
"199": "זה אינו ארכוב .sy.zip תקף. אם הארכוב ייצא מ[הגדרות], אנא ייבא אותו מ[הגדרות]",
|
||||
"200": "זמן התגובה של החיפוש הגלובלי איטי, מומלץ להוסיף סינון לפי סוג או מילות מפתח כדי לצמצם את טווח החיפוש",
|
||||
|
|
|
|||
|
|
@ -1644,7 +1644,7 @@
|
|||
"194": "<a href=\"https://help.jianguoyun.com/?p=2064\" target=\"_blank\">Ci sono restrizioni sull'interfaccia di Nutstore</a>, si prega di utilizzare altri servizi WebDAV",
|
||||
"195": "L'ora del sistema è errata, si prega di calibrare l'ora del sistema e riprovare",
|
||||
"196": "Non impostare il workspace sotto il percorso di un disco di sincronizzazione di terze parti, altrimenti i dati verranno danneggiati (iCloud/OneDrive/Dropbox/Google Drive/Nutstore/Baidu Netdisk/Tencent Weiyun, ecc.)",
|
||||
"197": "",
|
||||
"197": "Apri il taccuino [%s] e riprova",
|
||||
"198": "Questo non è un archivio dati valido. Se l'archivio è stato esportato da [Albero documenti], si prega di importarlo da [Albero documenti]",
|
||||
"199": "Questo non è un archivio .sy.zip valido. Se l'archivio è stato esportato da [Impostazioni], si prega di importarlo da [Impostazioni]",
|
||||
"200": "Il tempo di risposta della ricerca globale è lento, si consiglia di aggiungere filtri per tipo o parole chiave per restringere l'ambito della ricerca",
|
||||
|
|
|
|||
|
|
@ -1644,7 +1644,7 @@
|
|||
"194": "<a href=\"https://help.jianguoyun.com/?p=2064\" target=\"_blank\">Nutstore インターフェースには制限があります。</a>他の WebDAV サービスを使用してください",
|
||||
"195": "システム時刻が正しくありません。システム時刻を調整してから再試行してください",
|
||||
"196": "サードパーティの同期ディスクにワークスペースのパスを設定しないでください。設定するとデータが破損します (iCloud/OneDrive/Dropbox/Google Drive/Nutstore/Baidu Netdisk/Tencent Weiyun など)",
|
||||
"197": "",
|
||||
"197": "ノートブック [%s] を開いてから再試行してください",
|
||||
"198": "有効なデータアーカイブではありません。アーカイブが [ドキュメントツリー] からエクスポートされた場合は [ドキュメントツリー] からインポートしてください",
|
||||
"199": "有効な .sy.zip アーカイブではありません。アーカイブが [設定] からエクスポートされた場合は [設定] からインポートしてください",
|
||||
"200": "グローバル検索の応答時間が長いため、種類でフィルタするかキーワードで検索範囲を絞ることをお勧めします",
|
||||
|
|
|
|||
|
|
@ -1644,7 +1644,7 @@
|
|||
"194": "<a href=\"https://help.jianguoyun.com/?p=2064\" target=\"_blank\">Nutstore 인터페이스에 제한이 있습니다</a>. 다른 WebDAV 서비스를 사용하세요",
|
||||
"195": "시스템 시간이 올바르지 않습니다. 시스템 시간을 보정한 후 다시 시도하세요",
|
||||
"196": "타사 동기화 디스크 경로 아래에 작업 공간을 설정하지 마세요. 그렇지 않으면 데이터가 손상됩니다(iCloud/OneDrive/Dropbox/Google Drive/Nutstore/Baidu Netdisk/Tencent Weiyun 등)",
|
||||
"197": "",
|
||||
"197": "노트북 [%s]을(를) 연 뒤 다시 시도해 주세요",
|
||||
"198": "유효한 데이터 아카이브가 아닙니다. 아카이브를 [문서 트리]에서 내보낸 경우 [문서 트리]에서 가져오세요",
|
||||
"199": "유효한 .sy.zip 아카이브가 아닙니다. 아카이브를 [설정]에서 내보낸 경우 [설정]에서 가져오세요",
|
||||
"200": "전역 검색 응답 시간이 느립니다. 유형 필터링이나 키워드를 추가하여 검색 범위를 좁히는 것이 좋습니다",
|
||||
|
|
|
|||
|
|
@ -1644,7 +1644,7 @@
|
|||
"194": "<a href=\"https://help.jianguoyun.com/?p=2064\" target=\"_blank\">Zamienniki interfejsu Nutstore są ograniczone</a>, proszę używać innych usług WebDAV",
|
||||
"195": "Czas systemowy jest nieprawidłowy, proszę skalibrować czas systemowy i spróbować ponownie",
|
||||
"196": "Nie ustawiaj obszaru roboczego pod ścieżką zewnętrznego dysku synchronizującego, w przeciwnym razie dane ulegną uszkodzeniu (iCloud/OneDrive/Dropbox/Google Drive/Nutstore/Baidu Netdisk/Tencent Weiyun itp.)",
|
||||
"197": "",
|
||||
"197": "Proszę otworzyć notatnik [%s] i spróbować ponownie",
|
||||
"198": "To nie jest ważny archiwum. Jeśli archiwum zostało wyeksportowane z [Drzewa dokumentów], proszę zaimportować je iz [Drzewa dokumentów]",
|
||||
"199": "To nie jest ważny archiwum .sy.zip. Jeśli archiwum zostało wyeksportowane z [Ustawień], proszę zaimportować je z [Ustawień]",
|
||||
"200": "Czas reakcji wyszukiwania globalnego jest wolny, zaleca się dodanie filtrów typów lub słów kluczowych w celu zawężenia zakresu wyszukiwania",
|
||||
|
|
|
|||
|
|
@ -1644,7 +1644,7 @@
|
|||
"194": "<a href=\"https://help.jianguoyun.com/?p=2064\" target=\"_blank\">Há restrições na interface do Nutstore</a>, por favor use outros serviços WebDAV",
|
||||
"195": "O horário do sistema está incorreto, por favor calibre o horário do sistema e tente novamente",
|
||||
"196": "Não defina o espaço de trabalho sob o caminho de um disco de sincronização de terceiros, caso contrário os dados serão danificados (iCloud/OneDrive/Dropbox/Google Drive/Nutstore/Baidu Netdisk/Tencent Weiyun, etc.)",
|
||||
"197": "",
|
||||
"197": "Por favor, abra o caderno [%s] e tente novamente",
|
||||
"198": "Este não é um arquivo de dados válido. Se o arquivo foi exportado de [Árvore de Documentos], por favor importe de [Árvore de Documentos]",
|
||||
"199": "Este não é um arquivo .sy.zip válido. Se o arquivo foi exportado de [Configurações], por favor importe de [Configurações]",
|
||||
"200": "O tempo de resposta da busca global está lento, recomenda-se adicionar filtros de tipo ou palavras-chave para reduzir o escopo da busca",
|
||||
|
|
|
|||
|
|
@ -1644,7 +1644,7 @@
|
|||
"194": "<a href=\"https://help.jianguoyun.com/?p=2064\" target=\"_blank\">Есть ограничения интерфейса Nutstore</a>, пожалуйста, используйте другие службы WebDAV",
|
||||
"195": "Системное время неверно, пожалуйста, откалибруйте системное время и попробуйте снова",
|
||||
"196": "Не устанавливайте рабочее пространство в подкаталог синхронизации третьих лиц, иначе данные будут повреждены (iCloud/OneDrive/Dropbox/Google Drive/Nutstore/Baidu Netdisk/Tencent Weiyun и т.д.)",
|
||||
"197": "",
|
||||
"197": "Пожалуйста, откройте блокнот [%s] и попробуйте снова",
|
||||
"198": "Это не действительный архив данных. Если архив был экспортирован из [Дерево документов], пожалуйста, импортируйте его из [Дерево документов]",
|
||||
"199": "Это не действительный архив .sy.zip. Если архив был экспортирован из [Настройки], пожалуйста, импортируйте его из [Настройки]",
|
||||
"200": "Время отклика глобального поиска медленное, рекомендуется добавить фильтрацию по типу или ключевым словам для сужения области поиска",
|
||||
|
|
|
|||
|
|
@ -1644,7 +1644,7 @@
|
|||
"194": "<a href=\"https://help.jianguoyun.com/?p=2064\" target=\"_blank\">Nutstore arayüzünde kısıtlamalar vardır</a>, lütfen başka bir WebDAV hizmeti kullan",
|
||||
"195": "Sistem saati hatalı, lütfen düzeltip tekrar dene",
|
||||
"196": "Çalışma alanını üçüncü taraf senkron disk (iCloud/OneDrive/Dropbox/Google Drive/Nutstore/Baidu/Tencent vb.) altına koyma, aksi halde veri bozulur",
|
||||
"197": "",
|
||||
"197": "Lütfen [%s] defterini açtıktan sonra tekrar deneyin",
|
||||
"198": "Bu geçerli bir Veri arşivi değil. [Belge ağacı]ndan dışa aktardıysan aynı yerden içe aktar",
|
||||
"199": "Bu geçerli bir .sy.zip arşivi değil. [Ayarlar]dan dışa aktardıysan aynı yerden içe aktar",
|
||||
"200": "Genel arama yanıt süresi yavaş, arama kapsamını daraltmak için tür filtresi veya anahtar kelime eklemen önerilir",
|
||||
|
|
|
|||
|
|
@ -1644,7 +1644,7 @@
|
|||
"194": "<a href=\"https://help.jianguoyun.com/?p=2064\" target=\"_blank\">堅果雲接口存在限制</a>,請使用其他 WebDAV 服務",
|
||||
"195": "系統時間不正確,請校準系統時間後再試",
|
||||
"196": "請勿將工作空間設置在第三方同步硬碟路徑下,否則資料會被損壞(iCloud/OneDrive/Dropbox/Google Drive/堅果雲/百度網盤/騰訊微雲等)",
|
||||
"197": "",
|
||||
"197": "請打開筆記本 [%s] 後再試",
|
||||
"198": "這不是一個有效的 Data 壓縮檔。如果該資料檔是從 [文檔樹] 導出的,請從 [文檔樹] 導入",
|
||||
"199": "這不是一個有效的 .sy.zip 壓縮檔。如果該資料檔是從 [設置] 中導出的,請從 [設置] 中導入",
|
||||
"200": "全域搜索響應時間較慢,建議增加類型過濾或者增加關鍵字以縮小搜索範圍",
|
||||
|
|
|
|||
|
|
@ -1644,7 +1644,7 @@
|
|||
"194": "<a href=\"https://help.jianguoyun.com/?p=2064\" target=\"_blank\">坚果云接口存在限制</a>,请使用其他 WebDAV 服务",
|
||||
"195": "系统时间不正确,请校准系统时间后再试",
|
||||
"196": "请勿将工作空间设置在第三方同步盘路径下,否则数据会被损坏(iCloud/OneDrive/Dropbox/Google Drive/坚果云/百度网盘/腾讯微云等)",
|
||||
"197": "",
|
||||
"197": "请打开笔记本 [%s] 后再试",
|
||||
"198": "这不是一个有效的 Data 压缩包。如果该数据包是从 [文档树] 导出的,请从 [文档树] 导入",
|
||||
"199": "这不是一个有效的 .sy.zip 压缩包。如果该数据包是从 [设置] 中导出的,请从 [设置] 中导入",
|
||||
"200": "全局搜索响应时间较慢,建议增加类型过滤或者增加关键字以缩小搜索范围",
|
||||
|
|
|
|||
|
|
@ -33,6 +33,10 @@ export const initMessage = () => {
|
|||
|
||||
// type: info/error; timeout: 0 手动关闭;-1 永不关闭
|
||||
export const showMessage = (message: string, timeout = 6000, type = "info", messageId?: string) => {
|
||||
if (!message) {
|
||||
return;
|
||||
}
|
||||
|
||||
const messagesElement = document.getElementById("message").firstElementChild;
|
||||
if (!messagesElement) {
|
||||
let tempMessages = document.getElementById("tempMessage");
|
||||
|
|
|
|||
|
|
@ -665,6 +665,10 @@ func getBlockInfo(c *gin.Context) {
|
|||
ret.Code = -1
|
||||
ret.Msg = model.Conf.Language(275)
|
||||
return
|
||||
} else if errors.Is(err, model.ErrBoxUnindexed) {
|
||||
ret.Code = -1
|
||||
ret.Msg = ""
|
||||
return
|
||||
}
|
||||
|
||||
block, _ := model.GetBlock(id, tree)
|
||||
|
|
|
|||
|
|
@ -17,12 +17,17 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/88250/lute"
|
||||
|
|
@ -179,6 +184,7 @@ var (
|
|||
ErrBlockNotFound = errors.New("block not found")
|
||||
ErrTreeNotFound = errors.New("tree not found")
|
||||
ErrIndexing = errors.New("indexing")
|
||||
ErrBoxUnindexed = errors.New("notebook unindexed")
|
||||
)
|
||||
|
||||
func LoadTreeByBlockIDWithReindex(id string) (ret *parse.Tree, err error) {
|
||||
|
|
@ -195,14 +201,13 @@ func LoadTreeByBlockIDWithReindex(id string) (ret *parse.Tree, err error) {
|
|||
}
|
||||
|
||||
// 尝试从文件系统加载并建立索引
|
||||
indexTreeInFilesystem(id)
|
||||
|
||||
err = indexTreeInFilesystem(id)
|
||||
bt = treenode.GetBlockTree(id)
|
||||
if nil == bt {
|
||||
if "dev" == util.Mode {
|
||||
logging.LogWarnf("block tree not found [id=%s], stack: [%s]", id, logging.ShortStack())
|
||||
}
|
||||
return nil, ErrTreeNotFound
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -246,64 +251,53 @@ func loadTreeByBlockTree(bt *treenode.BlockTree) (ret *parse.Tree, err error) {
|
|||
|
||||
var searchTreeLimiter = rate.NewLimiter(rate.Every(3*time.Second), 1)
|
||||
|
||||
func indexTreeInFilesystem(rootID string) {
|
||||
func indexTreeInFilesystem(blockID string) error {
|
||||
if !searchTreeLimiter.Allow() {
|
||||
return
|
||||
return ErrIndexing
|
||||
}
|
||||
|
||||
msdID := util.PushMsg(Conf.language(45), 7000)
|
||||
defer util.PushClearMsg(msdID)
|
||||
|
||||
logging.LogWarnf("searching tree on filesystem [rootID=%s]", rootID)
|
||||
var treePath string
|
||||
filelock.Walk(util.DataDir, func(path string, d fs.DirEntry, err error) error {
|
||||
if d.IsDir() {
|
||||
if strings.HasPrefix(d.Name(), ".") {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
return nil
|
||||
}
|
||||
logging.LogWarnf("searching tree on filesystem [id=%s]", blockID)
|
||||
|
||||
if !strings.HasSuffix(d.Name(), ".sy") {
|
||||
return nil
|
||||
}
|
||||
|
||||
baseName := filepath.Base(path)
|
||||
if rootID+".sy" != baseName {
|
||||
return nil
|
||||
}
|
||||
|
||||
treePath = path
|
||||
return filepath.SkipAll
|
||||
})
|
||||
|
||||
if "" == treePath {
|
||||
logging.LogErrorf("tree not found on filesystem [rootID=%s]", rootID)
|
||||
return
|
||||
unindexedTreePath := findUnindexedTreePathInAllBoxes(blockID)
|
||||
if "" == unindexedTreePath {
|
||||
logging.LogInfof("tree not found on filesystem [id=%s]", blockID)
|
||||
return ErrTreeNotFound
|
||||
}
|
||||
|
||||
boxID := strings.TrimPrefix(treePath, util.DataDir)
|
||||
boxID := strings.TrimPrefix(unindexedTreePath, util.DataDir)
|
||||
boxID = boxID[1:]
|
||||
boxID = boxID[:strings.Index(boxID, string(os.PathSeparator))]
|
||||
treePath = strings.TrimPrefix(treePath, util.DataDir)
|
||||
treePath = strings.TrimPrefix(treePath, string(os.PathSeparator))
|
||||
treePath = strings.TrimPrefix(treePath, boxID)
|
||||
treePath = filepath.ToSlash(treePath)
|
||||
unindexedTreePath = strings.TrimPrefix(unindexedTreePath, util.DataDir)
|
||||
unindexedTreePath = strings.TrimPrefix(unindexedTreePath, string(os.PathSeparator))
|
||||
unindexedTreePath = strings.TrimPrefix(unindexedTreePath, boxID)
|
||||
unindexedTreePath = filepath.ToSlash(unindexedTreePath)
|
||||
if nil == Conf.Box(boxID) {
|
||||
for _, b := range Conf.GetClosedBoxes() {
|
||||
if b.ID == boxID {
|
||||
logging.LogInfof("box [%s] is closed", boxID)
|
||||
util.PushErrMsg(fmt.Sprintf(Conf.language(197), b.Name), 7000)
|
||||
return ErrBoxUnindexed
|
||||
}
|
||||
}
|
||||
|
||||
logging.LogInfof("box [%s] not found", boxID)
|
||||
// 如果笔记本不存在或者已经关闭,则不处理 https://github.com/siyuan-note/siyuan/issues/11149
|
||||
return
|
||||
// 如果笔记本不存在则不处理 https://github.com/siyuan-note/siyuan/issues/11149
|
||||
return ErrTreeNotFound
|
||||
}
|
||||
|
||||
tree, err := filesys.LoadTree(boxID, treePath, util.NewLute())
|
||||
tree, err := filesys.LoadTree(boxID, unindexedTreePath, util.NewLute())
|
||||
if err != nil {
|
||||
logging.LogErrorf("load tree [%s] failed: %s", treePath, err)
|
||||
return
|
||||
logging.LogErrorf("load tree [%s] failed: %s", unindexedTreePath, err)
|
||||
return err
|
||||
}
|
||||
|
||||
treenode.UpsertBlockTree(tree)
|
||||
sql.IndexTreeQueue(tree)
|
||||
logging.LogInfof("reindexed tree by filesystem [rootID=%s]", rootID)
|
||||
logging.LogInfof("reindexed tree by filesystem [blockID=%s]", blockID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadParentTree(tree *parse.Tree) (ret *parse.Tree) {
|
||||
|
|
@ -318,3 +312,111 @@ func loadParentTree(tree *parse.Tree) (ret *parse.Tree) {
|
|||
ret, _ = filesys.LoadTree(tree.Box, parentPath, luteEngine)
|
||||
return
|
||||
}
|
||||
|
||||
func findUnindexedTreePathInAllBoxes(id string) (ret string) {
|
||||
boxes := Conf.GetBoxes()
|
||||
for _, box := range boxes {
|
||||
root := filepath.Join(util.DataDir, box.ID)
|
||||
paths := findAllOccurrences(root, id)
|
||||
var rootIDs []string
|
||||
rootIDPaths := map[string]string{}
|
||||
for _, p := range paths {
|
||||
rootID := util.GetTreeID(p)
|
||||
rootIDs = append(rootIDs, rootID)
|
||||
rootIDPaths[rootID] = p
|
||||
}
|
||||
|
||||
result := treenode.ExistBlockTrees(rootIDs)
|
||||
for rootID, exist := range result {
|
||||
if !exist {
|
||||
return rootIDPaths[rootID]
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func findAllOccurrences(root string, target string) []string {
|
||||
if root == "" || target == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
searchBytes := []byte(target)
|
||||
jobs := make(chan string, 256) // 任务通道
|
||||
results := make(chan string, 256) // 结果通道
|
||||
|
||||
// 用于等待所有 Worker 完成
|
||||
var wg sync.WaitGroup
|
||||
// 用于等待结果收集器完成
|
||||
var collectWg sync.WaitGroup
|
||||
|
||||
// 1. 启动结果收集协程
|
||||
var matchedPaths []string
|
||||
collectWg.Add(1)
|
||||
go func() {
|
||||
defer collectWg.Done()
|
||||
for path := range results {
|
||||
matchedPaths = append(matchedPaths, path)
|
||||
}
|
||||
}()
|
||||
|
||||
// 2. 启动并发 Worker Pool (基于 CPU 核心数)
|
||||
numWorkers := runtime.NumCPU()
|
||||
for i := 0; i < numWorkers; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for path := range jobs {
|
||||
if containsTarget(path, searchBytes) {
|
||||
results <- path
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// 3. 遍历文件夹并分发任务
|
||||
_ = filepath.WalkDir(root, func(path string, d os.DirEntry, err error) error {
|
||||
if err == nil && d.Type().IsRegular() {
|
||||
jobs <- path
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
// 4. 关闭通道并等待结束
|
||||
close(jobs) // 停止分发任务
|
||||
wg.Wait() // 等待所有 Worker 处理完
|
||||
close(results) // 停止收集结果
|
||||
collectWg.Wait() // 等待切片组装完成
|
||||
|
||||
return matchedPaths
|
||||
}
|
||||
|
||||
// containsTarget 针对大文件优化的字节流匹配函数
|
||||
func containsTarget(path string, target []byte) bool {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// 1MB 缓冲区
|
||||
reader := bufio.NewReaderSize(f, 1024*1024)
|
||||
for {
|
||||
// 使用 ReadSlice 实现零拷贝读取
|
||||
line, err := reader.ReadSlice('\n')
|
||||
if len(line) > 0 && bytes.Contains(line, target) {
|
||||
return true
|
||||
}
|
||||
if err != nil {
|
||||
if err == bufio.ErrBufferFull {
|
||||
// 处理超过 1MB 的超长行,直接跳过当前行剩余部分
|
||||
for err == bufio.ErrBufferFull {
|
||||
_, err = reader.ReadSlice('\n')
|
||||
}
|
||||
continue
|
||||
}
|
||||
break // EOF 或其他错误
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue