AppFolio API 成本调优 | sed 's/\b(.)/\u\1/g'
概述
AppFolio Stack API 的定价基于合作伙伴协议。通过减少不必要的 API 调用来优化成本。
成本优化
- 积极缓存 — 物业/单元数据变化不频繁(5-15 分钟 TTL)
- 批量操作 — 一次获取所有租约,然后在本地过滤
- 增量同步 — 仅获取上次同步后修改过的记录
- 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 };
}
}