mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 14:43:46 +01:00
Merge pull request #28880 from overleaf/bg-add-time-option-to-clsi
add latexmk `-time` option to clsi and record performance logs GitOrigin-RevId: 467473859359913da73f83e10b63b45603ea175c
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
const crypto = require('node:crypto')
|
||||
|
||||
/**
|
||||
* Consistently sample a keyspace with a given sample percentage.
|
||||
* The same key will always produce a consistent percentile value that
|
||||
* can be compared against the sample percentage.
|
||||
* Example: if key is the userId and the samplePercentage is 10, then
|
||||
* we see all the activity for the 10% of users who are selected.
|
||||
*
|
||||
* @param {string} key - The unique identifier to be hashed and checked.
|
||||
* @param {number} samplePercentage - The percentage (0-100) of keys that should return true.
|
||||
* @returns {boolean} - True if the key is within the sample, false otherwise.
|
||||
*/
|
||||
function sampleByHash(key, samplePercentage) {
|
||||
if (samplePercentage <= 0) {
|
||||
return false
|
||||
}
|
||||
const hash = crypto.createHash('md5').update(key).digest()
|
||||
const hashValue = hash.readUInt32BE(0)
|
||||
const percentile = Math.floor((hashValue / 0xffffffff) * 100)
|
||||
return percentile < samplePercentage
|
||||
}
|
||||
|
||||
module.exports = { sampleByHash }
|
||||
Reference in New Issue
Block a user