AppFolio API コスト最適化 | sed 's/\b(.)/\u\1/g'
概要
AppFolio Stack API の価格体系はパートナー契約に基づきます。不要な API 呼び出しを減らすことでコストを最適化します。
コスト最適化
- 積極的にキャッシュする — 物件・ユニットデータはほとんど変更されません(TTL 5~15分)
- バッチ処理 — すべてのリースを一度に取得し、ローカルでフィルタリングする
- 増分同期 — 前回の同期以降に変更されたレコードのみを取得する
- ウェブフック駆動 — ポーリングではなくイベントに反応する
使用状況モニター
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 };
}
}