2014-04-05 29 views
9

我在应用程序中看到了一些平常的事情。没有理由,当我的流量很少或没有时,我的服务器会变慢。经过大量的反复试验,我发现我的问题在我的TastyPie资源上删除了ToOneField后消失了!如何停止TastyPie无缘无故地进行UPDATE查询?

我发现是因为某些未知原因TastyPie正在做数据库更新对这些ToOneFields没有很好的理由!什么......时刻!

enter image description here

我发现提起here一个可能的错误,声称已经解决了这一问题的更新。我已经安装了从pip的最新版本,但仍然看到此问题。

任何人都可以帮忙吗?

class IncentiveResource(ModelResource): 
    product_introducer = fields.ToOneField(ProductResource, 'referrer_product', full=True) 
    product_friend = fields.ToOneField(ProductResource, 'referee_product', full=True) 

    class Meta: 
     queryset = Incentive.objects.all().order_by('-date_created') 
     resource_name = 'incentive' 
     allowed_methods = ['get'] 
     authentication = MultiAuthentication(ClientAuthentication(), ApiKeyAuthentication()) 
     authorization = Authorization() 
     filtering = { 
      "active": ALL, 
     } 
     always_return_data = True 
     cache = SimpleCache(cache_name='resources', timeout=10) 

这里流量很少,但变得无法使用。 enter image description here enter image description here

+0

上面显示的性能分析输出......使用什么工具? – 8one6

+0

@ 8one6这是新的文物 – Prometheus

回答

2

我不知道这是否会帮助你,但我已经看到了一个应用程序我的工作,而在资源领域使用的查询集select_relatedfull=True轻微的性能提升。

尝试queryset = Incentive.objects.select_related('product_introducer', 'product_friend').all().order_by('-date_created')

+1

嗨法汉感谢您的答复。是的,我也读过这个,我认为这会有所帮助,但是,Tastypie没有正当理由地进行数据库更新是我最关心的事实。 – Prometheus

0

你能重现SQL更新在测试环境中?

如果是的话,这里是我会怎么调试它:

修改其中的SQL命令被执行源:插入一个assert声明没有更新得到执行。

如果assert失败,则会出现奇怪UPDATE的堆栈跟踪。

如果此堆栈跟踪不能帮助您,请将其发布到此处。