我有以下内容:
class Notification(ndb.Model):
targetUser = ndb.KeyProperty()
pointRoot = ndb.KeyProperty()
followReason = ndb.StringProperty()
notificationReason = ndb.StringProperty()
sourceUser = ndb.KeyProperty() # User who caused notification to be raised
raisedDate = ndb.DateTimeProperty(auto_now_add=True)
cleared = ndb.BooleanProperty(default=False)
clearedDate = ndb.DateTimeProperty(default=None)
@classmethod
def getActiveNotificationsForUser(cls, userKey):
q = cls.query(ndb.AND(cls.targetUser == userKey, cls.cleared == False))
q.order(-cls.raisedDate)
notifications = q.fetch(10)
return notifications
我认为这应该可行,因为它不使用不等式过滤器,只使用等式过滤器。当它不起作用时,我添加了一个索引,在 index.yaml 中定义如下:
- kind: Notification
properties:
- name: targetUser
- name: cleared
- name: raisedDate
direction: desc
但是,getActiveNotificationsForUser 仍然会乱序返回通知。
有谁知道为什么或我能做些什么来解决这个问题(没有得到所有通知并在 python 中排序)?
提前致谢,
- 亚伦