I’m really trying to break out of my RDBMS mind set when setting up my models/entities. I have a laser focus on performance, so I want to do this right. I have three distinct things I need to model:
Event – Happens on a date, has Person(s) invited to it, has Post(s) associated with it
Person – has a string id, has a name
Post – A Person will make a post for an Event. I need to keep the association between the Person who made the post, and the Event for which the Post was made.
My first thought was to go to something like
class Event
@PrimaryKey
Long id;
List<Key> personList;
List<Key> postList;
String name;
class Post
@PrimaryKey
Key id;
String details;
Key personWhoPosted;
class Person
@PrimaryKey
Key id;
String fbId;
String name;
The main query for the app loads all Events associated for a given Person.
I had this approach totally implemented, but as soon as the database started filling with a moderate amount of data from my beta testers, the action to load the main list slows to a crawl because there are SO MANY QUERYs and GETs happening. For every Event, I had to make another set of queries/gets for Posts. For for each Post I had to make a bunch of other queries/gets for the Person associated with it, and so on.
I’m using this video as my main reference:
http://www.youtube.com/watch?v=AgaL6NGpkB8&list=WLB3249928DA0FA4AF&feature=mh_lolz
What’s the best way to setup these relationships? I’m considering flattening everything out into Event in order to minimize the initial load to one query and a set of paralleled gets.
Without posting my full updated model here, the two driving factors I used to “make it right” were: using the correct key type, and using list properties to model indexes into the data. Here are two great references I found for this:
Clarification on which type for an entities key:
https://developers.google.com/appengine/docs/java/datastore/jdo/creatinggettinganddeletingdata#Keys
List properties as an efficient and performant way to retrieve data:
http://novyden.blogspot.com/2011/02/efficient-keyword-search-with-relation.html