【问题标题】:How can I stop TastyPie doing UPDATE queries for no reason?我怎样才能阻止 TastyPie 无缘无故地进行 UPDATE 查询?
【发布时间】:2014-04-05 21:33:59
【问题描述】:

我在我的应用程序中看到了一些常见的情况。当我的流量很少或没有流量时,我的服务器无缘无故变慢。经过大量试验和错误后,我发现当我删除我的TastyPie 资源上的ToOneField 时,我的问题消失了!

我发现出于某种未知原因,TastyPie 无缘无故对这些 ToOneFields 进行 数据库更新!什么...时刻!

我发现了一个可能的错误提交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)

这里的流量很少,但变得无法使用。

【问题讨论】:

  • 上面显示的分析输出...是什么工具做的?
  • @8one6 这是新遗物

标签: python django tastypie


【解决方案1】:

我不知道这是否会对您有所帮助,但我发现在我开发的应用程序中,在查询集中使用 select_related 并在资源字段中使用 full=True 时,性能略有提高。

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

【讨论】:

  • 您好 Farhan 感谢您的回复。是的,我也读过这篇文章,我认为这会有所帮助,但是,Tastypie 无缘无故地进行数据库更新这一事实是我的主要担忧。
【解决方案2】:

你能在测试环境中重现 sql UPDATE 吗?

如果是,这是我将如何调试它:

修改执行 sql 命令的源:插入不更新的assert 语句。

如果assert 失败,你有奇怪的 UPDATE 的堆栈跟踪。

如果此堆栈跟踪对您没有帮助,请在此处发布。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-31
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多