From e9d14e9e38316a1d6c5977292e749d0ebe25eb67 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Tue, 28 Oct 2025 17:18:22 -0400 Subject: [PATCH] no need to update api_key use date more than once per minute (#506) --- lib/models/api-key.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/models/api-key.js b/lib/models/api-key.js index 8e40ec3..f736984 100644 --- a/lib/models/api-key.js +++ b/lib/models/api-key.js @@ -47,10 +47,14 @@ class ApiKey extends Model { } /** - * update last_used api key for an account - */ + * update last_used api key for an account + * (only if last_used is null or more than a minute ago) + */ static updateLastUsed(account_sid) { - const sql = 'UPDATE api_keys SET last_used = NOW() WHERE account_sid = ?'; + const sql = `UPDATE api_keys + SET last_used = NOW() + WHERE account_sid = ? + AND (last_used IS NULL OR last_used < NOW() - INTERVAL 1 MINUTE)`; const args = [account_sid]; return new Promise((resolve, reject) => {