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

scalable randomization #7

Open
nonword opened this issue Jul 25, 2016 · 1 comment
Open

scalable randomization #7

nonword opened this issue Jul 25, 2016 · 1 comment

Comments

@nonword
Copy link
Contributor

nonword commented Jul 25, 2016

add random_no INT column to items table and index it. Set it to Math.round(Math.random()*ROUGHLY_TABLE_SIZE)) when creating a record (and consider updating it in a beforeUpdate hook - or whatever the node version of that is..)

That way we can select random items via:

var rnd = Math.random()
var pivot = rnd * ROUGHLY_TABLE_SIZE
var direction = rnd > 0.5 ? '>=' : '<'
var sql = `SELECT * FROM items WHERE random_no ${dir} ${pivot} LIMIT ${LIMIT}`

.. something like that..

@bertspaan
Copy link
Contributor

Thanks! Let's do this once we include more collections to Surveyor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants