我对Python世界比较陌生,但这看起来非常直截了当。如何优化此Google App Engine代码?
谷歌在我大呼小叫,需要进行优化验证码:
class AddLinks(webapp.RequestHandler):
def post(self):
# Hash the textarea input to generate pseudo-unique value
hash = md5.new(self.request.get('links')).hexdigest()
# Seperate the input by line
allLinks = self.request.get('links').splitlines()
# For each line in the input, add to the database
for x in allLinks:
newGroup = LinkGrouping()
newGroup.reference = hash
newGroup.link = x
newGroup.put()
# testing vs live
#baseURL = 'http://localhost:8080'
baseURL = 'http://linkabyss.appspot.com'
# Build template parameters
template_values = {
'all_links': allLinks,
'base_url': baseURL,
'reference': hash,
}
# Output the template
path = os.path.join(os.path.dirname(__file__), 'addLinks.html')
self.response.out.write(template.render(path, template_values))
仪表板是告诉我,这是使用一吨的CPU。
我应该在哪里寻求改进?
是,ListProperties有一个很酷的功能。如果您使用LinkGrouping.gql(“WHERE links =:1”,“http://www.google.com”),它将返回列表中包含“http://www.google.com”的所有群组。 – 2008-11-13 04:58:15