Model.get_by_key_name will call db.get:
@classmethod
def get_by_key_name(cls, key_names, parent=None, **kwargs):
"""Get instance of Model class by its key's name.
Args:
key_names: A single key-name or a list of key-names.
parent: Parent of instances to get. Can be a model or key.
"""
try:
parent = _coerce_to_key(parent)
except BadKeyError, e:
raise BadArgumentError(str(e))
rpc = datastore.GetRpcFromKwargs(kwargs)
key_names, multiple = datastore.NormalizeAndTypeCheck(key_names, basestring)
keys = [datastore.Key.from_path(cls.kind(), name, parent=parent)
for name in key_names]
if multiple:
return get(keys, rpc=rpc)
else:
return get(keys[0], rpc=rpc)
----------
keakon
2010/5/11 Pranny <[email protected]>:
> Is db.get() faster than Model.get_by_key_name()?
> Currently we are using Model.get_by_key_name for querying over a
> Model. Sometimes it takes unacceptable time, but mostly it is good
> enough. The Model has fewer than four attributes, all text. There is a
> lot of data that is stored using this model and it is being read too
> often (more than 15 ~20 reqs per second), However the write rate is
> quite less ( less than 1 req per second).
> Current steps :-
> 1. We create the keyname (One string addition operation)
> 2. We use Model.get_by_key_name
>
> Proposed steps :-
> 1. We create the keyname (One string addition)
> 2. We get the key from that keyname and the Model class, using
> Key.from_path()
> 3. We use db.get() and fetch the result.
>
> Correct me if i am wrong, but I think internally it goes via db.get()
> only and Model.get_by_key_name is an abstraction for that. So using
> db.get() will be faster and cheaper than Model.get_by_key_name.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.