I know this is simple but I couldn' figure this out, I am fetching all the instances for a given linkname but I want to call all their values(rating2) to perform a calculation, what I realized though is in looping through I believe this is making an individual call each time, (its slow) it takes 2 seconds for only 100 instances of the LinkRating2 class. So how would I call all of the rating2 values for a given linkname without a loop and populate a dictionary? Or quite frankly make this code faster?
class LinkRating2(db.Model):
user = db.StringProperty()
link = db.StringProperty()
rating2 = db.FloatProperty()
def sim_distance(link1,link2,tabl):
# Get the list of shared_items
si={}
query = tabl.all()
query2 = tabl.all()
a = query.filter('link = ', link1)
b = query2.filter('link = ', link2)
adic ={}
bdic= {}
##populate dics
aa = a.fetch(10000)
bb = b.fetch(10000)
for itema in aa:
adic[itema.user]=itema.rating2
for itemb in bb:
bdic[itemb.user]=itemb.rating2
EDIT:
ok I debugged and realized the loop is taking essentially 0 seconds, all my time is in the query and fetch lines, I only have a table with 100 items and it is taking 2 seconds!!!!! How can it be this slow to fetch a few items out of a 100 table and how can I speed this up?