|
|
@@ -1,6 +1,6 @@
|
|
|
const Settings = require('settings-sharelatex')
|
|
|
const _ = require('lodash')
|
|
|
-const { ObjectId } = require('mongodb')
|
|
|
+const crypto = require('crypto')
|
|
|
const OError = require('@overleaf/o-error')
|
|
|
|
|
|
const ACTIVE_SPLIT_TESTS = []
|
|
|
@@ -34,7 +34,7 @@ for (const splitTest of Settings.splitTests) {
|
|
|
function getTestSegmentation(userId, splitTestId) {
|
|
|
const splitTest = _.find(ACTIVE_SPLIT_TESTS, ['id', splitTestId])
|
|
|
if (splitTest) {
|
|
|
- let userIdAsPercentile = (ObjectId(userId).getTimestamp() / 1000) % 100
|
|
|
+ let userIdAsPercentile = _getPercentile(userId, splitTestId)
|
|
|
for (const variant of splitTest.variants) {
|
|
|
if (userIdAsPercentile < variant.rolloutPercent) {
|
|
|
return {
|
|
|
@@ -55,6 +55,15 @@ function getTestSegmentation(userId, splitTestId) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+function _getPercentile(userId, splitTestId) {
|
|
|
+ const hash = crypto
|
|
|
+ .createHash('md5')
|
|
|
+ .update(userId + splitTestId)
|
|
|
+ .digest('hex')
|
|
|
+ const hashPrefix = hash.substr(0, 8)
|
|
|
+ return Math.floor((parseInt(hashPrefix, 16) / 0xffffffff) * 100)
|
|
|
+}
|
|
|
+
|
|
|
module.exports = {
|
|
|
getTestSegmentation,
|
|
|
}
|