Closed jbriales closed 3 years ago
You can use nearly whichever format you want for IDs. Just make sure that it's not something like "timeFormat" or "strategySettings.customSidebar.items". Make sure there's no "." in it.
You just want to have enough entropy in your IDs that it's unlikely for there to be a collision. At a minimum I'd take 13 alphanumeric characters (upper+lower), which is about 77 bits of entropy. Then you'd need to create about 500 million tasks before you'd have a one-in-a-million chance of a collision. Or maybe I calculated that wrong, but something like that. 20 is quite safe :).
Marvin's IDs are created differently in different places, but it uses this when creating tasks using the desktop app's local API server (with length=14):
const RAND_CHARS = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
const randId = (len) => {
if (len <= 0) {
return "";
}
let str = "";
for (let i = 0; i < len; i++) {
const n = Math.floor(Math.random()*RAND_CHARS.length);
str += RAND_CHARS[n];
}
return str;
};
As per title: I'm creating tasks directly in PouchDB, rather than through the Marvin API. I noticed normal Task ids look like
yjtbuXPphzKGs79EE574
(i.e. 20 alphanumeric chars, lower and upper case) and Project ids look like UUIDs. When creating our own tasks, is it relevant which format the_id
follows? Could you point to the exact library/function used for generating each in case this is relevant to produce ours in the same way?