In my app's views.py file, I have three views. I've pasted the whole
views.py below, with passwords replaced.
The second and third view both get some data from a page that uses the
first view. The first view downloads data from a web service.
For some reason, the third view is much, much slower than the second
view, even though the third view is much simpler... and even though
the second view ostensibly does everything the third view does and
more.
A page utilizing the second view consistently loads in about 2
seconds. A page utilizing the much simpler third view consistently
takes 20+ seconds to load. Any idea why the third view is so slow?
As you can see below, I'm using the per-view cache on all three views.
Thanks,
Ryan
from django.shortcuts import render_to_response
from django.http import HttpResponse
from xml.etree.ElementTree import ElementTree
from django.views.decorators.cache import cache_page
import urllib, base64, subprocess, os
from django.contrib import auth
@cache_page(30 * 60)
def reg_all(request, user, password):
user = auth.authenticate(username=user, password=password)
if user is not None:
service_url = '
http://www.something.com/etc/
user=something&pass=somethingelse'
xml = urllib.urlopen(service_url)
tree = ElementTree()
xml_doc = tree.parse(xml)
datum = ""
for node in xml_doc.getiterator():
datum = "%s" % (node.text)
decoded = base64.b64decode(datum)
dir = '/path/to/myproject/regdata/data/'
if os.path.exists(dir+'data'):
r = os.unlink(dir+'data')
if os.path.exists(dir+'data.zip'):
r = os.unlink(dir+'data.zip')
f = open(dir+'data.zip', 'wb')
f.write(decoded)
f.close()
file = subprocess.call('unzip '+dir+'data.zip -d '+dir,
shell=True)
file = open(dir+'data', 'rb').read()
txt = file.decode('utf_16_le')
txt = txt.replace('</Registration>','</Registration>\n')
txt = '<RegAll>\n'+txt+'</RegAll>'
return render_to_response('reg_all.html',{
'output' : txt
})
else:
return render_to_response('output.html',{
'output' : 'authentication failed'
})
@cache_page(30 * 60)
def read_xml(request, user, password):
xml = urllib.urlopen('
http://this.org/reg_all/u='+user+'/
p='+password)
xml = xml.read()
txt = unicode(xml)
if txt != 'authentication failed':
dir = '/path/to/myproject/regdata/'
if os.path.exists(dir+'temp.txt'):
r = os.unlink(dir+'temp.txt')
f = open(dir+'temp.txt','w')
f.write(txt)
f.close()
tree = ElementTree()
xml_doc = tree.parse(dir+'temp.txt')
datum = ""
for node in xml_doc.getiterator():
datum = "%s<br />%s - %s" % (datum, node.tag, node.text)
output = datum
else:
output = 'auth failed'
return render_to_response('output.html',{
'output' : output
})
@cache_page(30 * 60)
def reg_all_xml(request, user, password):
xml = urllib.urlopen('
http://this.org/reg_all/u='+user+'/
p='+password)
xml = xml.read()
txt = unicode(xml)
if txt != 'authentication failed':
output = txt
else:
output = 'auth failed'
return render_to_response('output.html',{
'output' : output
})