appfolio 成本調校
概述
AppFolio Stack API 的定價是基於合作夥伴協議。透過減少不必要的 API 呼叫來最佳化成本。
成本最佳化
- 積極快取 — 財產/單位資料很少變動(TTL 5-15 分鐘)
- 批次操作 — 一次擷取所有租約,在本地端過濾
- 增量同步 — 僅擷取自上次同步以來修改過的記錄
- Webhook 驅動 — 回應事件而非輪詢
用量監控
class ApiUsageMonitor {
private calls: Array<{ endpoint: string; timestamp: number }> = [];
record(endpoint: string) { this.calls.push({ endpoint, timestamp: Date.now() }); }
getHourlyReport() {
const cutoff = Date.now() - 3600000;
const recent = this.calls.filter(c => c.timestamp > cutoff);
const byEndpoint: Record<string, number> = {};
for (const c of recent) byEndpoint[c.endpoint] = (byEndpoint[c.endpoint] || 0) + 1;
return { total: recent.length, byEndpoint };
}
}