I'm working on converting an application from db to ndb, and am working on making my queries more efficient. The application has become a bit slow with the increase in amount of data, causing us to realize that the queries are pretty inefficient.
Background:
Our stripped-down data model is similar to this (feel free to criticize):
class ServiceRequest(ndb.Model):
technician = ndb.UserProperty()
application = ndb.KeyProperty() # ServiceRequestApplication kind
class ServiceRequestApplication(ndb.Model):
applicant = ndb.UserProperty()
Admins can "approve" a ServiceRequestApplication for a ServiceRequest. ServiceRequestApplications are instantiated with a parent ServiceRequest. If a ServiceRequestApplication is approved, the application's key is stored in the request's application property.
The tricky part:
There can be multiple ServiceRequest entities for 1 actual service appointment (1 per technician). We have one ServiceRequest, and if there are multiple techs needed, we create additional ServiceRequests, with the main ServiceRequest as a parent. We originally approached the problem this way because ancestor queries would be pretty easy, including some other reasons with regards to the way this data was going to be queried/represented.
Can anyone think of a way to query for ServiceRequest entities that don't have children ServiceRequests?
Thanks!