我對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