Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache results from getUsernameHistory #852

Merged
merged 7 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/users/getUsernameHistory.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Includes
const getPageResults = require('../util/getPageResults.js').func
const cache = require('../cache')

// Args
exports.required = ['userId']
Expand All @@ -11,7 +12,7 @@ exports.optional = ['limit', 'sortOrder', 'pageCursor']
* @category User
* @alias getUsernameHistory
* @param {number} userId
* @param {Limit=} [limit=10]
* @param {Limit=} [limit=100]
* @param {SortOrder=} [sortOrder=Asc]
* @param {string} cursor
* @returns {Promise<UsernameHistoryEntry[]>}
Expand All @@ -31,5 +32,11 @@ function getUsernameHistory (userId, limit, sortOrder, cursor) {
}

exports.func = function (args) {
return getUsernameHistory(args.userId, args.limit, args.sortOrder, args.cursor)
let { userId, limit, sortOrder, cursor } = args
limit ||= 100
sortOrder ||= 'Asc'

return cache.wrap('UsernameHistory', `${userId}-${limit}-${sortOrder}-${cursor}`, function () {
return getUsernameHistory(userId, limit, sortOrder, cursor)
})
}
6 changes: 6 additions & 0 deletions settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@
"expire": false,
"refresh": false,
"desc": "Caches rank by user ID. Changes cannot be anticipated so this is not enabled by default."
},

"UsernameHistory": {
"expire": 86400,
"refresh": false,
"desc": "Caches a user's username history based on user id, limit, sort order, and cursor. The rate limit for the associated endpoint is very low, and this setting should be left alone as a result."
}
}
}
Loading