2014-04-05 33 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的堆棧跟蹤。

如果此堆棧跟蹤不能幫助您,請將其發佈到此處。