mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
fix(server): infinite loop in note map
This commit is contained in:
parent
f718e87673
commit
58a883797d
@ -57,7 +57,7 @@ describe("Note map service", () => {
|
|||||||
{
|
{
|
||||||
excerpts: [
|
excerpts: [
|
||||||
trimIndentation`\
|
trimIndentation`\
|
||||||
<div class="ck-content backlink-excerpt"><head></head><body><p>
|
<div class="ck-content backlink-excerpt"><p>
|
||||||
The quick brownie
|
The quick brownie
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
@ -68,14 +68,14 @@ describe("Note map service", () => {
|
|||||||
<figure class="image">
|
<figure class="image">
|
||||||
${" "}
|
${" "}
|
||||||
</figure>
|
</figure>
|
||||||
</body></div>`
|
</div>`
|
||||||
],
|
],
|
||||||
noteId: "first",
|
noteId: "first",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
excerpts: [
|
excerpts: [
|
||||||
trimIndentation`\
|
trimIndentation`\
|
||||||
<div class="ck-content backlink-excerpt"><head></head><body><p>
|
<div class="ck-content backlink-excerpt"><p>
|
||||||
<a class="reference-link backlink-link" href="#root/dUtgloZIckax">
|
<a class="reference-link backlink-link" href="#root/dUtgloZIckax">
|
||||||
Backlink text
|
Backlink text
|
||||||
</a>
|
</a>
|
||||||
@ -90,7 +90,7 @@ describe("Note map service", () => {
|
|||||||
Second
|
Second
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
</body></div>`
|
</div>`
|
||||||
],
|
],
|
||||||
noteId: "second"
|
noteId: "second"
|
||||||
}
|
}
|
||||||
|
@ -243,8 +243,8 @@ function updateDescendantCountMapForSearch(noteIdToDescendantCountMap: Record<st
|
|||||||
|
|
||||||
function removeImages(document: HTMLElement) {
|
function removeImages(document: HTMLElement) {
|
||||||
const images = document.getElementsByTagName("img");
|
const images = document.getElementsByTagName("img");
|
||||||
while (images && images.length > 0) {
|
for (const image of images) {
|
||||||
images[0]?.parentNode?.removeChild(images[0]);
|
image.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,9 +257,13 @@ export function findExcerpts(sourceNote: BNote, referencedNoteId: string) {
|
|||||||
|
|
||||||
const excerpts: string[] = [];
|
const excerpts: string[] = [];
|
||||||
|
|
||||||
|
console.log("Removing images")
|
||||||
removeImages(document);
|
removeImages(document);
|
||||||
|
|
||||||
|
console.log("Querying links");
|
||||||
|
|
||||||
for (const linkEl of document.querySelectorAll("a")) {
|
for (const linkEl of document.querySelectorAll("a")) {
|
||||||
|
console.log("Got ", linkEl.innerHTML);
|
||||||
const href = linkEl.getAttribute("href");
|
const href = linkEl.getAttribute("href");
|
||||||
|
|
||||||
if (!href || !href.endsWith(referencedNoteId)) {
|
if (!href || !href.endsWith(referencedNoteId)) {
|
||||||
@ -271,6 +275,7 @@ export function findExcerpts(sourceNote: BNote, referencedNoteId: string) {
|
|||||||
let centerEl: HTMLElement = linkEl;
|
let centerEl: HTMLElement = linkEl;
|
||||||
|
|
||||||
while (centerEl.tagName !== "BODY" && centerEl.parentNode && (centerEl.parentNode?.textContent?.length || 0) <= EXCERPT_CHAR_LIMIT) {
|
while (centerEl.tagName !== "BODY" && centerEl.parentNode && (centerEl.parentNode?.textContent?.length || 0) <= EXCERPT_CHAR_LIMIT) {
|
||||||
|
console.log("Got ", centerEl.tagName, centerEl.parentNode);
|
||||||
centerEl = centerEl.parentNode;
|
centerEl = centerEl.parentNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,6 +371,7 @@ function getBacklinks(req: Request): BacklinksResponse {
|
|||||||
let backlinksWithExcerptCount = 0;
|
let backlinksWithExcerptCount = 0;
|
||||||
|
|
||||||
return getFilteredBacklinks(note).map((backlink) => {
|
return getFilteredBacklinks(note).map((backlink) => {
|
||||||
|
console.log("Processing ", backlink);
|
||||||
const sourceNote = backlink.note;
|
const sourceNote = backlink.note;
|
||||||
|
|
||||||
if (sourceNote.type !== "text" || backlinksWithExcerptCount > 50) {
|
if (sourceNote.type !== "text" || backlinksWithExcerptCount > 50) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user