@@ -456,42 +456,45 @@ export class Plugin extends PluginBase<PluginTypes> {
456456 processItem : async ( note ) => {
457457 cachedFilePaths . delete ( note . path ) ;
458458 if ( this . frontmatterMarkdownLinksCache . isCacheValid ( note ) ) {
459- const links = this . frontmatterMarkdownLinksCache . getLinks ( note ) ;
460- if ( links . length > 0 ) {
461- const cache = await getCacheSafe ( this . app , note ) ;
462- if ( cache ) {
463- cache . frontmatterLinks ??= [ ] ;
464- const currentLinks = new Map < string , FrontmatterLinkCache > ( ) ;
465-
466- for ( const link of cache . frontmatterLinks ) {
467- currentLinks . set ( link . key , link ) ;
468- }
459+ const frontmatterMarkdownLinksCacheLinks = this . frontmatterMarkdownLinksCache . getLinks ( note ) ;
460+ if ( frontmatterMarkdownLinksCacheLinks . length === 0 ) {
461+ return ;
462+ }
463+ const cache = await getCacheSafe ( this . app , note ) ;
464+ if ( ! cache ) {
465+ return ;
466+ }
467+ cache . frontmatterLinks ??= [ ] ;
469468
470- const linkKeys = new Set ( links . map ( ( link ) => link . key ) ) ;
471- filterInPlace ( cache . frontmatterLinks , ( link ) => ! linkKeys . has ( link . key ) ) ;
472-
473- const newLinks : FrontmatterLinkCache [ ] = [ ] ;
474-
475- for ( const link of links ) {
476- const currentLink = currentLinks . get ( link . key ) ;
477- if ( currentLink && currentLink . original !== link . original ) {
478- cache . frontmatterLinks . push ( currentLink ) ;
479- this . frontmatterMarkdownLinksCache . deleteKey ( note . path , link . key ) ;
480- continue ;
481- }
482-
483- if ( cache . frontmatter && getNestedPropertyValue ( cache . frontmatter , link . key ) instanceof String ) {
484- cache . frontmatterLinks . push ( link ) ;
485- newLinks . push ( link ) ;
486- } else {
487- this . frontmatterMarkdownLinksCache . deleteKey ( note . path , link . key ) ;
488- }
489- }
469+ const obsidianLinkMap = new Map < string , FrontmatterLinkCache > ( ) ;
470+
471+ for ( const link of cache . frontmatterLinks ) {
472+ obsidianLinkMap . set ( link . key , link ) ;
473+ }
490474
491- for ( const link of newLinks ) {
492- this . updateResolvedOrUnresolvedLinksCache ( link . link , note . path ) ;
475+ const frontmatterMarkdownLinksCacheKeys = new Set ( frontmatterMarkdownLinksCacheLinks . map ( ( link ) => link . key ) ) ;
476+ filterInPlace ( cache . frontmatterLinks , ( link ) => ! frontmatterMarkdownLinksCacheKeys . has ( link . key ) ) ;
477+
478+ const newLinks : FrontmatterLinkCache [ ] = [ ] ;
479+
480+ for ( const link of frontmatterMarkdownLinksCacheLinks ) {
481+ const value = getNestedPropertyValue ( cache . frontmatter ?? { } , link . key ) ;
482+ if ( value !== link . original ) {
483+ this . frontmatterMarkdownLinksCache . deleteKey ( note . path , link . key ) ;
484+ const obsidianLink = obsidianLinkMap . get ( link . key ) ;
485+ if ( obsidianLink ) {
486+ cache . frontmatterLinks . push ( obsidianLink ) ;
487+ obsidianLinkMap . delete ( link . key ) ;
493488 }
489+ continue ;
494490 }
491+
492+ cache . frontmatterLinks . push ( link ) ;
493+ newLinks . push ( link ) ;
494+ }
495+
496+ for ( const link of newLinks ) {
497+ this . updateResolvedOrUnresolvedLinksCache ( link . link , note . path ) ;
495498 }
496499 return ;
497500 }
0 commit comments