abeauseigle / TodoApp

A webSqlApp syncing with a php MySQL server
1 stars 6 forks source link

BDBid increase uniqueness #2

Closed luigi37 closed 9 years ago

luigi37 commented 9 years ago

Hi Alain, the BDBid feature looks very cool. In order to reduce the (remote) chance of overlapping of the BDBid can any or both of the following be done? 1- Use milliseconds instead of seconds 2- add a random value in a certain range (0-999) If only one option I'd rather the second.... Thanks!

abeauseigle commented 9 years ago

Hi Luigi, I did a search about Php timestamp and your millisecond option. I found something that we could experiment. See http://stackoverflow.com/questions/3656713/how-to-get-current-time-in-milliseconds-in-php I'll put it in my Todo list for a future improvement. Or you can suggest me the code to do it, because I pretty busy this time. Ciao!

luigi37 commented 9 years ago

I added a certain deegree with randomness in the code with a pull request. Considering APP it would be great of we could use the unique identifier of the phone as an option...

abeauseigle commented 9 years ago

For sure, adding the device identifyer to the BDBid would eliminate totally the chance of double user with the same BDBid. For my usage (I aim to do a timesheet app for 200 users, not a public app), I think the chance to have 2 users with the same BDBid is very slight if we use millisecond instead of second. Remember that it's one BDBid per user, not per transaction.

luigi37 commented 9 years ago

Right Alain, my point is more academic then a real case. Still i think it would be very cool if the bdbid would be calculated OR if it could be provided to the function. First case good for browsers, second for apps for which you could even recover status in case of reinstall on same device. Did you get my pull request? Does it sound right? Instead of real millisec it uses a random number between 0 and 999. Ciao. Luigi

abeauseigle commented 9 years ago

I implemented the timestamp in millisecond and it works very well with a bonus... I just replaced the line: //$this -> serverAnswer['syncDate'] = strtotime("now")1000; // return sync_date: "1234567890000", (gives only seconds, not milliseconds) By this one: $this -> serverAnswer['syncDate'] = round(microtime(true) \ 1000); // return sync_date: "1234567890123", microtime() returns the Unix timestamp, with microseconds. This function is only available on server supporting the function gettimeofday().

The advantage is that it also increase the precision of the last sync date time of the "transactions". And it's cleaner than client side. I'll update the Git in the next few days.

luigi37 commented 9 years ago

It seems to work well... Once uploaded in the repository I will close this. Thanks

luigi37 commented 9 years ago

After several days of testing it seems to be all good. I updated "webSqlSyncHandlre.php" in my fork. Thanks