1qazxsw2
1qazxsw2

Reputation: 2789

Getting a GAE datastore single entity, which is more efficient

Which is more CPU efficient, 1, 2 or 3?

key = something.key()
id = something.key().id()

1) db.GqlQuery("select.....").fetch(1)[0]

2) db.get(key)

3) get_by_id(id)

Upvotes: 0

Views: 198

Answers (1)

Nick Johnson
Nick Johnson

Reputation: 101149

Option 1 is less efficient, because it requires a query. Incidentally, note that if you want exactly one result, you can call get() on the Query, which will return the first result, or None if there are none.

2 and 3 are identical; get_by_id is just syntactic sugar for constructing a key and fetching it with get.

Upvotes: 5

Related Questions