[英]Comparing Non MySQL List/Array/Data With MySQL rows?
I'm developing an iOS social networking app. 我正在开发一个iOS社交应用程序。 I'm currently building "Find Friends" section.
我目前正在建立“查找朋友”部分。
I have a "users" table which is something like this: 我有一个“用户”表,它是这样的:
-user_id -user_name ... -twitter_id -facebook_id -instagram_id
948913 yagiz 2134421 2132412 4314124312
Now for example when I try to find friends, app does this in the background: 现在,例如,当我尝试寻找朋友时,应用程序会在后台执行此操作:
Get the list of whole followings of current user from selected social networking app(Twitter/Facebook/Instagram). 从选定的社交网络应用程序(Twitter / Facebook / Instagram)获取当前用户的全部关注者列表。 Response is a simple array which consists of user ids.
响应是一个由用户ID组成的简单数组。
For each Twitter/Facebook/Instagram id run a query that checks if it is in app database. 对于每个Twitter / Facebook / Instagram id,运行一个查询,检查它是否在应用程序数据库中。
Currently this works well. 目前,这很好。 But I kinda think that this isn't efficient.
但是我有点认为这不是有效的方法。 Because if the user follows 5K people on Twitter/Facebook/Instagram app runs 5K query.
因为如果用户关注5K,则Twitter / Facebook / Instagram应用程序上的人员将运行5K查询。
So I'm asking which is the best way to compare non MySQL list/array/data with MySQL rows? 所以我想问比较非MySQL列表/数组/数据和MySQL行的最佳方法是什么?
You can perform a single query using 您可以使用进行单个查询
WHERE ... IN('1', '2')
If you have an array of the ids , you can do it like this: 如果您具有ID数组,则可以这样操作:
$twitterIds = array(
1234,
1235,
1236
);
// $twitterIdString = '1234','1235','1236'
$twitterIdString = "'" . implode("','", $twitterIds) . "'";
// $queryStub = WHERE `-twitter_id` IN('1234','1235','1236')
$queryStub = "WHERE `-twitter_id` IN(" . $twitterIdString . ")";
This will return only the twitter users that are in your database. 这将仅返回数据库中的twitter用户。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.