Intersection on Google App Engine

蓝咒 提交于 2019-12-24 08:47:38

问题


When a user Facebook Connects to my site, I want to narrow down the list of the user's Facebook friends to just those that have already signed up for my website.

So I have two lists

  • A list in code of a user's facebook friends (around 1000)
  • A GAE table of all FB users that have signed up for my site (around 1000)

Is the most efficient way to do this to do a single query for the UIDs of all signed up FB users and do the intersection in code?

What would be the most efficient way if there were more like 10,000 FB users signed up where they couldn't all be retrieved by queries in < 30 seconds?


回答1:


Turn the problem around on it's head slightly. When a user logs in, fetch his friends list and store the facebook numeric ids in an list property on the user's object. (You could also use an index object... look at the talk by Brett Slatkin on doing fan-out in GAE.)

Something like

class User:
  friend_ids = db.ListProperty()

When a new user logs in, just do a query and filter on friend_ids = :id. This should give you a list of existing users who are friends of your current user. Which I believe is actually what you want.

The user query filtered on a list property will return a user if the id you're querying for is contained in the list, in case you're not familiar with that. Docs are here.



来源:https://stackoverflow.com/questions/4890042/intersection-on-google-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!