Custom Keys

27 views
Skip to first unread message

Henry Kiss

unread,
May 5, 2016, 3:39:46 AM5/5/16
to Firebase + EmberJS
Hi,


I have control over writes from a single source and after reviewing some of Firebase's own Open Data Sets schema, I had expected to use custom keys rather than the default generated keys.  I will be writing a dozen attributes for two hundred entities each second over several hours.  I had intended to use a unix timestamp as the key as I will be querying against that to retrieve the data for playback in the client application.

In terms of performance, is it worth the effort to investigate customizing the serializer, or should I just supply the timestamp as an attribute and use .indexOn?


Thanks,
Wayne

Tim Stirrat

unread,
May 5, 2016, 10:01:43 PM5/5/16
to Henry Kiss, Firebase + EmberJS
Hi Wayne,

If you wanted to use a different ID generation mechanism you can override generateIdForRecord in a serializer associated with a single model type in ember like this:

// adapters/mymodel.js
import FirebaseAdapter from 'emberfire/adapters/firebase';

export default FirebaseAdapter.extend({
  generateIdForRecord() {
    return '' + new Date().getTime();
  },
});

Keep in mind that you will need to account for ID collisions. Using our generated IDs will give you collision resistance with chronological ordering.

I will try to get more info for you pertaining to .indexOn

Tim

--
You received this message because you are subscribed to the Google Groups "Firebase + EmberJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-embe...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jonny Dimond

unread,
May 6, 2016, 1:36:57 PM5/6/16
to Firebase + EmberJS, mr.hen...@gmail.com
Hi Wayne,

regarding .indexOn: There should not be a big difference between using .indexOn and querying by key. Both do their indexing very similarly. We do suggest you use the generated push IDs as they are battle tested.

Jonny
Reply all
Reply to author
Forward
0 new messages