Backlink Cache

approved

by Michael Naumov

Store backlink cache to speed up `app.metadataCache.getBacklinksForFile`.

52 stars26,713 downloadsUpdated 15d agoMIT

Backlink Cache

Buy Me a Coffee GitHub release GitHub downloads Coverage: 100%

This is a plugin for Obsidian that maintains backlink cache to speed up undocumented app.metadataCache.getBacklinksForFile() function.

It's mostly useful for users with the large vaults. On smaller vaults the difference might be unnoticeable.

It speeds up Backlinks Pane performance and plugins that deal with the backlinks.

This plugin the most likely will be useful for other plugin developers that deal with the backlinks.

Its idea came from the forum.

Also the plugin includes canvas (.canvas) files in the backlinks for the referenced notes, and exposes a canvas file's links through app.metadataCache.getCache(). See Canvas backlinks.

Usage

Fast version

The provided version is faster than the built-in version. Also the overload to accept path was added.

const backlinks1 = app.metadataCache.getBacklinksForFile(file);
const backlinks2 = app.metadataCache.getBacklinksForFile(path);

Safe version

If you want to ensure the all recent file changes are processed and the backlinks are 100% accurate.

const backlinks1 = await app.metadataCache.getBacklinksForFile.safe(file);
const backlinks2 = await app.metadataCache.getBacklinksForFile.safe(path);

Original version

You can access the original built-in version:

const backlinks = app.metadataCache.getBacklinksForFile.originalFn(file);

TypeScript typings

If you want to use the updated functions from your plugin, you can copy types.d.ts into your code.

Canvas backlinks

Obsidian resolves canvas backlinks natively since v1.12.4: links from canvas file/text cards appear in the Backlinks pane and graph, and in app.metadataCache.getBacklinksForFile() and resolvedLinks / unresolvedLinks.

On top of that, the plugin keeps canvas files in its fast backlink index and additionally exposes each canvas file's links through app.metadataCache.getCache(), which Obsidian leaves empty for canvas files. This runs when the Canvas core plugin is enabled.

Backlinks panel

The plugin speeds up the Backlinks panel if Backlinks core plugin is enabled.

Frontmatter markdown links

The plugin includes backlinks from the frontmatter markdown links if Frontmatter Markdown Links community plugin is enabled. Example of such link:

---
key: "[title](path/to/link.md)"
---

Demo vault

A demo vault with usage examples ships with every release. You can access it via any of the following:

  1. Running the Backlink Cache: Open demo vault command.
  2. Downloading backlink-cache-demo-vault-<version>.zip (<version> is the release version) from the Releases.
  3. Browsing its source in demo-vault/ in this repository.

Installation

The plugin is available in the official Community Plugins repository.

Beta versions

To install the latest beta release of this plugin (regardless if it is available in the official Community Plugins repository or not), follow these steps:

  1. Ensure you have the BRAT plugin installed and enabled.
  2. Click Install via BRAT.
  3. An Obsidian pop-up window should appear. In the window, click the Add plugin button once and wait a few seconds for the plugin to install.

Debugging

By default, debug messages for this plugin are hidden.

To show them, run the following command:

window.DEBUG.enable('backlink-cache');

For more details, refer to the documentation.

Support

Buy Me A Coffee

My other Obsidian resources

See my other Obsidian resources.

License

© Michael Naumov

For plugin developers

Search results and similarity scores are powered by semantic analysis of your plugin's README. If your plugin isn't appearing for searches you'd expect, try updating your README to clearly describe your plugin's purpose, features, and use cases.