在Google App Engine上优化我的Django应用 [英] Optimizing my Django app on Google App Engine

查看:95
本文介绍了在Google App Engine上优化我的Django应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在优化Django应用的特定用例.我的第一步是用ValuesQuerySet替换QuerySet.这工作得很好,但我想做更多.现在,我正在考虑使用Memcache(该应用程序正在Google App Engine上运行).所以我的计划是基本上将ValuesQuerySet放在Memcache中.但是据我了解,ValueQuerySet基本上是尚未实现的数据结构.为了使缓存正常工作,ValueQuerySet需要先实现,然后再放入Memcache.

I'm optimising a particular use case of my Django app. My first step was to replace a QuerySet with a ValuesQuerySet. This worked quite well but I want to do more. Now I'm considering using Memcache (the app is running on Google App Engine). So my plan is to basically put the ValuesQuerySet in Memcache. However it is my understanding that ValueQuerySet is basically a not yet materialised data structure. In order for the cache to work, the ValueQuerySet needs to materialise first and then put in the Memcache.

根据 Django文档:

list(). Force evaluation of a QuerySet by calling list() on it.

和:

Finally, note a ValuesQuerySet is a subclass of QuerySet, so it has all methods of QuerySet.

但是当我尝试my_values_qs.list()时,它会引发异常:

But when I try my_values_qs.list() it throws an exception:

AttributeError: 'ValuesQuerySet' object has no attribute 'list'

因此,尽管ValuesQuerySetQuerySet的子类,但显然不能list()其内容.如果为真,则意味着Django文档是错误的或至少具有误导性.

So, although ValuesQuerySet is a subclass of QuerySet it apparently cannot list() its contents. Which, if true, would mean that the Django docs are wrong or at least misleading.

我是否缺少某些内容,或者文档确实不对吗?实现ValueQuerySet结果以便将其存储在Memcache中的最佳方法是什么?

Am I missing something or are the docs indeed wrong? What would be the best way to materialise the result of ValueQuerySet so that I can store it in Memcache?

推荐答案

您从文档中误读了这一点.它没有说调用queryset.list()方法":它说了对其调用list()".换句话说,调用list(my_queryset)而不是my_queryset.list()-实际上,这将在随后的示例中明确说明.

You're misreading that bit from the docs. It doesn't say "call the queryset.list() method": it says "call list() on it". In other words, call list(my_queryset), not my_queryset.list() - and in fact that is explicitly illustrated with an example immediately afterwards.

请注意,这与子类化无关:QuerySet也不具有list()方法.

Note that this has nothing to do with subclassing: QuerySet doesn't have a list() method either.

这篇关于在Google App Engine上优化我的Django应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆