简体   繁体   中英

Filtering app engine data from datastore dynamically

My app-engine data model is defined as:

class Event(db.Model):
    title = db.LinkProperty();
    refresh_interval = db.IntegerProperty(); 

class EventSchedule(db.Model):
    event = db.ReferenceProperty(Event)     # referencing the event
    refresh_date = db.DateTimeProperty();   # date & time of last successful refresh 

I'd like to fetch all EventSchedule items based on the criteria of:

event_schedule.refresh_date + event.refresh_interval >= now

In SQL-land, it would look something like: DATE_ADD(event_schedule.refresh_date, event.refreshInterval) >= now()

Is this kind of join operation feasible with the data store?

This join operation is not possible with the GAE data store, and is highly inefficient on normal SQL databases as well (since it requires a scan of the entire event_schedule table).

You should instead store a next_refresh DateTimeProperty in your EventSchedule entities, initialized to be refresh_date + refresh_interval when the entity is created, and simply test for next_refresh >= now .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM