speed up calling lot of entities, and getting unique values, google app engine python

Posted by user291071 on Stack Overflow See other posts from Stack Overflow or by user291071
Published on 2010-05-24T21:11:20Z Indexed on 2010/05/24 23:21 UTC
Read the original article Hit count: 193

Filed under:
|

OK this is a 2 part question, I've seen and searched for several methods to get a list of unique values for a class and haven't been practically happy with any method so far.
So anyone have a simple example code of getting unique values for instance for this code. Here is my super slow example.

class LinkRating2(db.Model):
    user = db.StringProperty()
    link = db.StringProperty()
    rating2 = db.FloatProperty()

def uniqueLinkGet(tabl):
    start = time.time()
    dic = {}
    query = tabl.all()
    for obj in query:
        dic[obj.link]=1
    end = time.time()
    print end-start
    return dic

My second question is calling for instance an iterator instead of fetch slower? Is there a faster method to do this code below? Especially if the number of elements called be larger than 1000?

query = LinkRating2.all()
link1 = 'some random string'
a = query.filter('link = ', link1)
adic ={}
for itema in a:
    adic[itema.user]=itema.rating2

© Stack Overflow or respective owner

Related posts about python

Related posts about google-app-engine