Tôi tương đối mới với thế giới python, nhưng điều này có vẻ rất thẳng về phía trước.Tôi làm cách nào để tối ưu hóa mã Google App Engine này?
Google đang la hét với tôi rằng mã này cần phải được tối ưu hóa:
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))
Các bảng điều khiển là nói cho tôi rằng điều này là sử dụng một tấn của CPU.
Tôi nên tìm cải tiến ở đâu?
Vâng, ListProperties có một tính năng mát mẻ. Nếu bạn làm LinkGrouping.gql ("WHERE links =: 1", "http://www.google.com"), nó sẽ trả về tất cả các nhóm có 'http://www.google.com' trong danh sách của họ. –