obsidian-cost-tuning
Optimize Obsidian plugin resource usage and external service costs. Use when managing API quotas, reducing storage usage, or optimizing sync and external service consumption. Trigger with phrases like "obsidian resources", "obsidian quota", "optimize obsidian storage", "reduce obsidian costs".
Install
mkdir -p .claude/skills/obsidian-cost-tuning && curl -L -o skill.zip "https://mcp.directory/api/skills/download/1602" && unzip -o skill.zip -d .claude/skills/obsidian-cost-tuning && rm skill.zipInstalls to .claude/skills/obsidian-cost-tuning
About this skill
Obsidian Cost Tuning
Overview
Optimize resource consumption and external service costs for Obsidian plugins that use APIs, storage, or sync services.
Prerequisites
- Plugin with external API integrations
- Understanding of API pricing models
- Access to usage metrics
Resource Categories
Cost Drivers
| Resource | Optimization Target | Impact |
|---|---|---|
| API calls | Minimize requests | High |
| Data storage | Compress and dedupe | Medium |
| Sync bandwidth | Reduce transfer size | Medium |
| Compute | Cache results | Low |
Instructions
Step 1: API Request Optimization
// src/services/api-optimizer.ts
import { requestUrl } from 'obsidian';
interface CacheEntry<T> {
data: T;
timestamp: number;
etag?: string;
}
export class OptimizedAPIClient {
private cache = new Map<string, CacheEntry<any>>();
private pendingRequests = new Map<string, Promise<any>>();
private cacheTTL: number;
constructor(cacheTTLMs: number = 5 * 60 * 1000) { // 5 min default
this.cacheTTL = cacheTTLMs;
}
async get<T>(url: string, options: {
bypassCache?: boolean;
customTTL?: number;
} = {}): Promise<T> {
const cacheKey = url;
// Check cache
if (!options.bypassCache) {
const cached = this.cache.get(cacheKey);
const ttl = options.customTTL ?? this.cacheTTL;
if (cached && Date.now() - cached.timestamp < ttl) {
console.log(`[Cache] HIT: ${url}`);
return cached.data as T;
}
}
// Deduplicate concurrent requests
const pending = this.pendingRequests.get(cacheKey);
if (pending) {
console.log(`[Request] DEDUPE: ${url}`);
return pending as Promise<T>;
}
// Make request
const requestPromise = this.makeRequest<T>(url, cacheKey);
this.pendingRequests.set(cacheKey, requestPromise);
try {
return await requestPromise;
} finally {
this.pendingRequests.delete(cacheKey);
}
}
private async makeRequest<T>(url: string, cacheKey: string): Promise<T> {
const cached = this.cache.get(cacheKey);
const headers: Record<string, string> = {};
// Use ETags for conditional requests
if (cached?.etag) {
headers['If-None-Match'] = cached.etag;
}
const response = await requestUrl({
url,
headers,
throw: false,
});
// Not modified - use cached data
if (response.status === 304 && cached) {
console.log(`[Request] NOT MODIFIED: ${url}`);
this.cache.set(cacheKey, {
...cached,
timestamp: Date.now(),
});
return cached.data as T;
}
// Store new data
const etag = response.headers['etag'];
this.cache.set(cacheKey, {
data: response.json,
timestamp: Date.now(),
etag,
});
console.log(`[Request] FETCHED: ${url}`);
return response.json as T;
}
clearCache(): void {
this.cache.clear();
}
getCacheStats(): { size: number; entries: number } {
let size = 0;
for (const entry of this.cache.values()) {
size += JSON.stringify(entry.data).length;
}
return { size, entries: this.cache.size };
}
}
Step 2: Request Batching
// src/services/batch-requester.ts
export class BatchRequester<T, R> {
private queue: Array<{ input: T; resolve: (r: R) => void; reject: (e: Error) => void }> = [];
private batchTimeout: NodeJS.Timeout | null = null;
private batchProcessor: (inputs: T[]) => Promise<R[]>;
private maxBatchSize: number;
private batchDelayMs: number;
constructor(
batchProcessor: (inputs: T[]) => Promise<R[]>,
options: { maxBatchSize?: number; batchDelayMs?: number } = {}
) {
this.batchProcessor = batchProcessor;
this.maxBatchSize = options.maxBatchSize ?? 20;
this.batchDelayMs = options.batchDelayMs ?? 50;
}
async request(input: T): Promise<R> {
return new Promise((resolve, reject) => {
this.queue.push({ input, resolve, reject });
if (this.queue.length >= this.maxBatchSize) {
this.processBatch();
} else if (!this.batchTimeout) {
this.batchTimeout = setTimeout(() => this.processBatch(), this.batchDelayMs);
}
});
}
private async processBatch(): Promise<void> {
if (this.batchTimeout) {
clearTimeout(this.batchTimeout);
this.batchTimeout = null;
}
const batch = this.queue.splice(0, this.maxBatchSize);
if (batch.length === 0) return;
try {
const inputs = batch.map(item => item.input);
const results = await this.batchProcessor(inputs);
batch.forEach((item, index) => {
item.resolve(results[index]);
});
} catch (error) {
batch.forEach(item => {
item.reject(error as Error);
});
}
}
}
// Usage: Batch multiple API lookups into single request
const batcher = new BatchRequester<string, NoteMetadata>(
async (noteIds: string[]) => {
// Single API call for multiple items
const response = await api.getNotes(noteIds);
return response.notes;
}
);
// Individual calls are automatically batched
const note1 = await batcher.request('note-1');
const note2 = await batcher.request('note-2');
Step 3: Storage Optimization
// src/services/storage-optimizer.ts
export class StorageOptimizer {
// Compress data before storing
static compress(data: any): string {
const json = JSON.stringify(data);
// Simple compression: remove whitespace and use shorter keys
// For production, use actual compression library
return json
.replace(/\s+/g, '')
.replace(/"([^"]+)":/g, (_, key) => {
// Use single-char keys for common fields
const shortKeys: Record<string, string> = {
'path': 'p',
'name': 'n',
'content': 'c',
'modified': 'm',
'created': 'r',
'tags': 't',
};
return `"${shortKeys[key] || key}":`;
});
}
// Decompress stored data
static decompress(compressed: string): any {
const longKeys: Record<string, string> = {
'p': 'path',
'n': 'name',
'c': 'content',
'm': 'modified',
'r': 'created',
't': 'tags',
};
const expanded = compressed.replace(/"([pncmrt])":/g, (_, key) => {
return `"${longKeys[key]}":`;
});
return JSON.parse(expanded);
}
// Deduplicate repeated strings
static deduplicateStrings<T extends object>(data: T[]): { data: T[]; dictionary: string[] } {
const dictionary: string[] = [];
const stringIndex = new Map<string, number>();
const indexedData = data.map(item => {
const indexed: any = {};
for (const [key, value] of Object.entries(item)) {
if (typeof value === 'string' && value.length > 10) {
let index = stringIndex.get(value);
if (index === undefined) {
index = dictionary.length;
dictionary.push(value);
stringIndex.set(value, index);
}
indexed[key] = `$${index}`;
} else {
indexed[key] = value;
}
}
return indexed;
});
return { data: indexedData, dictionary };
}
// Calculate storage savings
static calculateSavings(original: any, optimized: any): {
originalSize: number;
optimizedSize: number;
savingsPercent: number;
} {
const originalSize = JSON.stringify(original).length;
const optimizedSize = JSON.stringify(optimized).length;
const savingsPercent = ((originalSize - optimizedSize) / originalSize) * 100;
return { originalSize, optimizedSize, savingsPercent };
}
}
Step 4: Rate Limiting with Quotas
// src/services/quota-manager.ts
interface QuotaConfig {
dailyLimit: number;
monthlyLimit: number;
perMinuteLimit: number;
}
export class QuotaManager {
private config: QuotaConfig;
private usage: {
daily: { count: number; date: string };
monthly: { count: number; month: string };
perMinute: number[];
};
private storageKey: string;
constructor(plugin: Plugin, config: QuotaConfig) {
this.config = config;
this.storageKey = 'api-quota-usage';
this.usage = this.loadUsage(plugin);
}
private loadUsage(plugin: Plugin): typeof this.usage {
const saved = plugin.loadData()?.[this.storageKey];
const today = new Date().toISOString().split('T')[0];
const month = today.substring(0, 7);
return {
daily: saved?.daily?.date === today
? saved.daily
: { count: 0, date: today },
monthly: saved?.monthly?.month === month
? saved.monthly
: { count: 0, month },
perMinute: [],
};
}
async canMakeRequest(): Promise<{ allowed: boolean; reason?: string; waitMs?: number }> {
const now = Date.now();
// Check per-minute limit
this.usage.perMinute = this.usage.perMinute.filter(t => now - t < 60000);
if (this.usage.perMinute.length >= this.config.perMinuteLimit) {
const oldestRequest = this.usage.perMinute[0];
const waitMs = 60000 - (now - oldestRequest);
return {
allowed: false,
reason: `Rate limit: ${this.config.perMinuteLimit} requests/minute`,
waitMs,
};
}
// Check daily limit
if (this.usage.daily.count >= this.config.dailyLimit) {
return {
allowed: false,
reason: `Daily limit reached: ${this.config.dailyLimit} requests`,
};
}
// Check monthly limit
if (this.usage.monthly.count >= this.config.monthlyLimit) {
return {
allowed: false,
reason: `Monthly limit reached: ${this.config.monthlyLimit} requests`,
};
}
return { allowed: true };
}
recordRequest(): void {
const now = Date.now();
this.usage.perMinute.push(now);
this.usage.daily.count++;
this.usage.monthly.count++;
}
getUsageStats(): {
daily: { used: number; limit: number; percent: number };
monthly: { used: number; limit: number; percent:
---
*Content truncated.*
More by jeremylongshore
View all skills by jeremylongshore →You might also like
flutter-development
aj-geddes
Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.
ui-ux-pro-max
nextlevelbuilder
"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."
drawio-diagrams-enhanced
jgtolentino
Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.
godot
bfollington
This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.
nano-banana-pro
garg-aayush
Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.
pdf-to-markdown
aliceisjustplaying
Convert entire PDF documents to clean, structured Markdown for full context loading. Use this skill when the user wants to extract ALL text from a PDF into context (not grep/search), when discussing or analyzing PDF content in full, when the user mentions "load the whole PDF", "bring the PDF into context", "read the entire PDF", or when partial extraction/grepping would miss important context. This is the preferred method for PDF text extraction over page-by-page or grep approaches.
Related MCP Servers
Browse all servers1MCP Agent simplifies configuration management by unifying MCP servers, lowering resource use, and enabling dynamic conf
Funnel is a TypeScript proxy server that aggregates MCP servers, intelligently filtering tools to optimize context token
Integrate Terraform Registry with infrastructure as code tools for seamless provider lookup, module recommendations, and
Obsidian Semantic delivers smart Obsidian vault management with intelligent file access, editing, and adaptive indexing
Enhance your Obsidian workflow with this plugin using Local REST API for advanced search, note access, and vault structu
Enhance your workflow with Obsidian Advanced, the ultimate Obsidian plugin for note management, automation, and advanced
Stay ahead of the MCP ecosystem
Get weekly updates on new skills and servers.