Google App Engine 的index 機制

在存取DB item 時如果涉及到兩個以上的 欄位, 例如:

query = Page.all()
query.filter("in_official_page_pool =", True)
query.order('-access_time')

(若不做任何處理就deploy code, 會產生 internal server error
這個DB 查詢造成的錯誤)

以上就涉及 in_official_page_pool 和 access_time 兩個欄位
此時就要在專案根目錄的index.yaml 新增以下片段

- kind: Page
  properties:
  - name: in_official_page_pool
  - name: access_time
    direction: desc

此舉會驅使GAE 去建立 in_official_page_pool 對上 access_time 的index
建立時間不長, 大約五分鐘就好了

留言

熱門文章