fix: remove duplication

This commit is contained in:
soulsands 2023-04-08 20:00:42 +08:00
parent 49d1c5140e
commit 50043f889b

View File

@ -2,7 +2,7 @@ const becca = require('./becca');
const log = require('../services/log'); const log = require('../services/log');
const beccaService = require('./becca_service'); const beccaService = require('./becca_service');
const dateUtils = require('../services/date_utils'); const dateUtils = require('../services/date_utils');
const { JSDOM } = require("jsdom"); const {JSDOM} = require("jsdom");
const DEBUG = false; const DEBUG = false;
@ -168,7 +168,6 @@ function trimMime(mime) {
} }
mimeCache[mime] = str; mimeCache[mime] = str;
mimeCache[mime] = str;
} }
return mimeCache[mime]; return mimeCache[mime];
@ -224,8 +223,8 @@ function splitToWords(text) {
*/ */
function hasConnectingRelation(sourceNote, targetNote) { function hasConnectingRelation(sourceNote, targetNote) {
return sourceNote.getAttributes().find(attr => attr.type === 'relation' return sourceNote.getAttributes().find(attr => attr.type === 'relation'
&& ['includenotelink', 'imagelink'].includes(attr.name) && ['includenotelink', 'imagelink'].includes(attr.name)
&& attr.value === targetNote.noteId); && attr.value === targetNote.noteId);
} }
async function findSimilarNotes(noteId) { async function findSimilarNotes(noteId) {
@ -301,7 +300,7 @@ async function findSimilarNotes(noteId) {
for (const branch of parentNote.getParentBranches()) { for (const branch of parentNote.getParentBranches()) {
score += gatherRewards(branch.prefix, 0.3) score += gatherRewards(branch.prefix, 0.3)
+ gatherAncestorRewards(branch.parentNote); + gatherAncestorRewards(branch.parentNote);
} }
} }
} }
@ -314,7 +313,7 @@ async function findSimilarNotes(noteId) {
function computeScore(candidateNote) { function computeScore(candidateNote) {
let score = gatherRewards(trimMime(candidateNote.mime)) let score = gatherRewards(trimMime(candidateNote.mime))
+ gatherAncestorRewards(candidateNote); + gatherAncestorRewards(candidateNote);
if (candidateNote.isDecrypted) { if (candidateNote.isDecrypted) {
score += gatherRewards(candidateNote.title); score += gatherRewards(candidateNote.title);
@ -382,7 +381,7 @@ async function findSimilarNotes(noteId) {
score += 1; score += 1;
} }
else if (utcDateCreated.substr(0, 10) === dateLimits.minDate.substr(0, 10) else if (utcDateCreated.substr(0, 10) === dateLimits.minDate.substr(0, 10)
|| utcDateCreated.substr(0, 10) === dateLimits.maxDate.substr(0, 10)) { || utcDateCreated.substr(0, 10) === dateLimits.maxDate.substr(0, 10)) {
if (displayRewards) { if (displayRewards) {
console.log("Adding reward for same day of creation"); console.log("Adding reward for same day of creation");
} }