如何在数据存储区上有效地获取“关系”元素?

问题描述 投票:0回答:1

我正在使用Google数据存储区开发社交登录系统。我需要使用其社交身份对用户进行身份验证,然后返回其所有身份的信息。客户可以使用多个社交帐户登录,也可以使用在我的网站上创建的身份登录,因此它基本上具有多个社交身份以及我的网站身份。目前,我正在使用(依次)运行3个查询,我觉得这有点太多了,所以我想知道是否有更好的方法可以做到这一点:

// get the username registered with my site(if is registered)
     - userID  = SELECT userID From social WHERE socialID == $socialID
// get the data of the user
     - userData = SELECT * from MyData WHERE userID == userID
// get the data of any other identity it uses / has linked to the user id
     - otherSocial = select * FROM social WHERE userID=userID and socialID != $socialID
google-app-engine google-cloud-datastore
1个回答
1
投票
  1. 您可以通过其键获取userData,它比运行查询更快,更便宜。为了能够做到这一点,您应该使用userId作为userData的ID。

  2. 您的第三个查询可能仅在少数情况下才需要,例如当用户访问帐户设置时。无论哪种情况,我都不必担心这些查询:它们检索少量实体,这意味着它们执行得非常快。

  3. 您可以在一个会话中存储一些数据,因此在下一个会话之前不必检索它。我存储一个LoginOption实体,它等效于您的userId和socialId。因此,我可以绕过第一个查询,直到用户注销或会话过期。

© www.soinside.com 2019 - 2024. All rights reserved.