Query executed two times in database (django 1.4, oracle 11g)

2013-09-08 Thread Germán
I'm not familiar with caching internals but perhaps the fact that you are using 
`raw` has something to do with your problem?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Query executed two times in database (django 1.4, oracle 11g)

2013-09-06 Thread bikeridercz
Dear colleagues,

I'm facing a problem probably related to caching infrastructure in DJango. 
Documentation says that data are fetched from DB once a then readed from 
cache.

However, my results are different. Query is executed two times. On my 
opinion the first fetch should be enough.

Here is a record from my debug log:

[06/Sep/2013 08:35:11] "GET /mvpn/waves/OSCAR_MVPN/ HTTP/1.1" 200 2316
DEBUG (11.092) select /*+ first_rows */rownum id, t.* from 
ngin_mvpn_wave_cdr_sum t where t.wave_id=:arg0 order by vpn_name; 
args=[u'OSCAR_MVPN'] 11.092076 select /*+ first_rows */rownum id, t.* 
from ngin_mvpn_wave_cdr_sum t where t.wave_id=:arg0 order by vpn_name 
[u'OSCAR_MVPN']
DEBUG (10.353) select /*+ first_rows */rownum id, t.* from 
ngin_mvpn_wave_cdr_sum t where t.wave_id=:arg0 order by vpn_name; 
args=[u'OSCAR_MVPN'] 10.352256 select /*+ first_rows */rownum id, t.* 
from ngin_mvpn_wave_cdr_sum t where t.wave_id=:arg0 order by vpn_name 
[u'OSCAR_MVPN']
[06/Sep/2013 08:35:35] "GET /mvpn/waves/OSCAR_MVPN/cdr/ HTTP/1.1" 200 19515


The problem is, that one execution takes 11 seconds what is acceptable 
result for business. However 20s is not. Query was already optimized - huge 
number of records from several tables is processed.

What I'm doing on view level:

...

mvpn_cdr = MVPN_WAVE_CDR_SUM.objects.raw('select /*+ first_rows */rownum 
id, t.* from ngin_mvpn_wave_cdr_sum t where t.wave_id=%s order by 
vpn_name', [wave_id])

... 

for i in mvpn_cdr:

count_moc_onnet = count_moc_onnet + i.count_moc_onnet

...

return render_to_response('ngin/mvpn_wave_cdr_sum.html', {'resultset': 
mvpn_cdr}, context_instance=c)


So, I think that "filter" method should fetch data from DB and put it into 
QuerySet cache. Further use of data should be taken from a cache.

Yes, It's fact that I was not setting any cache configuration before.

Please help or explain what I'm doing wrong.

Radim.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.