Re: [] Re: queryset caching - without caching middleware

2012-07-05 Thread Tom Evans
On Thu, Jul 5, 2012 at 4:08 PM, Henrik Genssen  wrote:
>>Could you show where and how you are executing the query? If the
>>queryset is a global, and does not go out of scope at the end of the
>>request, then reusing the queryset will not cause the queryset to be
>>re-evaluated.
>>
>>Eg, in this example, categories is a global outside of the view, and
>>once evaluated, will not be re-evaluated just because you used it in a
>>view.
>>
>>categories = Category.objects.all()
>>
>>def index(request):
>>  return render_to_response('index.html': { 'categories': categories })
>>
>>When querysets are executed is documented here:
>>
>>https://docs.djangoproject.com/en/1.4/ref/models/querysets/#when-querysets-are-evaluated
>
>
> yep, global caught me.
> I have a class:
>
> class table(object):
>queryset = Category.objects.all()
>column1 = ...
>column2 = ...
>
>def render(self):
>   return '...'
>
> in a view I am doing:
>
> tbl = table()
> # somtimes adding filters
> tbl.queryset = tbl.queryset.filter(...)
>
>
> I want to create a html table like "forms" in django
>
> Is it enough to call the all() method on the queryset in my rendering method 
> to get the queryset query the db again?
>
> regards
>
> Henrik
>

Yes, so that queryset is created once, when the class definition is
parsed, and then populated once. Regardless of how many instances of
table that you create, they all get the same object, created when the
class was parsed.

The simplest solution would be to simply assign that queryset inside
the init method, instead of making it a class member, eg:

class table(object):
   column1 = ...
   column2 = ...
   def __init__(self):
 self.queryset = Category.objects.all()

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



RE: [] Re: queryset caching - without caching middleware

2012-07-05 Thread Henrik Genssen
>Could you show where and how you are executing the query? If the
>queryset is a global, and does not go out of scope at the end of the
>request, then reusing the queryset will not cause the queryset to be
>re-evaluated.
>
>Eg, in this example, categories is a global outside of the view, and
>once evaluated, will not be re-evaluated just because you used it in a
>view.
>
>categories = Category.objects.all()
>
>def index(request):
>  return render_to_response('index.html': { 'categories': categories })
>
>When querysets are executed is documented here:
>
>https://docs.djangoproject.com/en/1.4/ref/models/querysets/#when-querysets-are-evaluated


yep, global caught me.
I have a class:

class table(object):
   queryset = Category.objects.all()
   column1 = ...
   column2 = ...

   def render(self):
  return '...'

in a view I am doing:

tbl = table()
# somtimes adding filters
tbl.queryset = tbl.queryset.filter(...)


I want to create a html table like "forms" in django

Is it enough to call the all() method on the queryset in my rendering method to 
get the queryset query the db again?

regards

Henrik

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: queryset caching - without caching middleware

2012-07-05 Thread Tom Evans
On Thu, Jul 5, 2012 at 3:49 PM, Melvyn Sopacua  wrote:
> On 5-7-2012 14:28, hinnack wrote:
>> - can I disable or force a "refresh" of the cache?
>
> 
>

Transactions/READ REPEATED behaviour is unlikely to be affecting him
across requests, since the DB connection is opened and closed at the
start and end of each request.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: queryset caching - without caching middleware

2012-07-05 Thread Melvyn Sopacua
On 5-7-2012 14:28, hinnack wrote:
> - can I disable or force a "refresh" of the cache?



-- 
Melvyn Sopacua


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: queryset caching - without caching middleware

2012-07-05 Thread Tom Evans
On Thu, Jul 5, 2012 at 1:28 PM, hinnack  wrote:
> hmm, Ok, Queryset Caching happens alle the time...
>
> So here are some more questions on this:
> - where is the data stored?
> - can I ask a model, if its result is cached or a fresh one?
> - can I disable or force a "refresh" of the cache?
> - how would i use a query in a property of a class, without running into the
> cache phenomena?
>
> regards
>
> Henrik
>

Could you show where and how you are executing the query? If the
queryset is a global, and does not go out of scope at the end of the
request, then reusing the queryset will not cause the queryset to be
re-evaluated.

Eg, in this example, categories is a global outside of the view, and
once evaluated, will not be re-evaluated just because you used it in a
view.

categories = Category.objects.all()

def index(request):
  return render_to_response('index.html': { 'categories': categories })

When querysets are executed is documented here:

https://docs.djangoproject.com/en/1.4/ref/models/querysets/#when-querysets-are-evaluated

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: queryset caching - without caching middleware

2012-07-05 Thread hinnack
hmm, Ok, Queryset Caching happens alle the time...

So here are some more questions on this:
- where is the data stored?
- can I ask a model, if its result is cached or a fresh one?
- can I disable or force a "refresh" of the cache?
- how would i use a query in a property of a class, without running into 
the cache phenomena?

regards

Henrik


Am Donnerstag, 5. Juli 2012 13:43:06 UTC+2 schrieb hinnack:
>
> Hi all, 
>
> what's the magic here? 
>
> I am using django 1.3 with sqlite or postgres by invoking: 
> runserver 10.150.2.15:8080 --noreload 
>
> I have a view (no cache decorator) doing simple querys on the orm and 
> return that as html - nothing fancy 
> The view is executed on each request, but the database is hit only on the 
> first request 
> After that devserver shows only one query each request querying for 
> django_session 
>
> newly data is not fetched... 
>
> any idea? 
>
> my middleware looks like this: 
> MIDDLEWARE_CLASSES = ( 
> 'django.middleware.common.CommonMiddleware', 
> 'django.contrib.sessions.middleware.SessionMiddleware', 
> 'schiwago.middleware.header.ResponseInjectHeader', 
> 'schiwago.middleware.auth.BasicAuthMiddleware', 
> 'django.middleware.transaction.TransactionMiddleware', 
> ) 
>
> INSTALLED_APPS = ( 
> 'django.contrib.auth', 
> 'django.contrib.contenttypes', 
> 'django.contrib.sessions', 
> 'django.contrib.messages', 
> 'django.contrib.staticfiles', 
> 'django.contrib.admin', 
> 'schiwago', 
> 'transdb', 
> 'south', 
> 'mediafactory.ui', 
> 'relatorio', 
> 'djcelery', 
> 'devserver' 
> ) 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/RYl7--t81FIJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



queryset caching - without caching middleware

2012-07-05 Thread Henrik Genssen
Hi all,

what's the magic here?

I am using django 1.3 with sqlite or postgres by invoking: 
runserver 10.150.2.15:8080 --noreload

I have a view (no cache decorator) doing simple querys on the orm and return 
that as html - nothing fancy
The view is executed on each request, but the database is hit only on the first 
request
After that devserver shows only one query each request querying for 
django_session

newly data is not fetched...

any idea?

my middleware looks like this:
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'schiwago.middleware.header.ResponseInjectHeader',
'schiwago.middleware.auth.BasicAuthMiddleware',
'django.middleware.transaction.TransactionMiddleware',
)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'schiwago',
'transdb',
'south',
'mediafactory.ui',
'relatorio',
'djcelery',
'devserver'
)


regards

Henrik

Henrik Genssen

h...@miadi.net
Tel. +49 (0)451/6195650
Fax. +49 (0)451/6195655
http://www.miadi.net
http://www.facebook.com/pages/Miadi/150192061701844

miadi GmbH
Geschäftsführer: Henrik Genssen
Sitz der Gesellschaft: Hüxstraße 1 - 9, 23552 Lübeck
Amtsgericht Lübeck HRB 10223, USt-IdNr DE
Lieferungen und Leistungen erfolgen ausschließlich auf Grundlage unserer 
allgemeinen Geschäftsbedingungen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.