FQL多查询优化
我正在尝试思考是否可以使用 FQL 多重查询而不是多个 API 调用来执行某些操作。
这是我的代码:
var queries : Object = {
"user_list":"SELECT uid2 FROM friend WHERE uid1 = "+uid
,"event_id":"SELECT eid, start_time, end_time, location, pic, name FROM event
WHERE eid IN (SELECT eid FROM event_member
WHERE uid IN (SELECT uid2 FROM #user_list)
AND rsvp_status='attending') AND start_time > " + nowSecs + "
AND start_time < " + (nowSecs + 2500000) + " ORDER BY start_time ASC LIMIT 20"
"user_name":"SELECT name FROM user
WHERE uid IN (SELECT uid FROM event_member
WHERE eid IN (SELECT eid FROM #event_id)
AND uid IN (SELECT uid2 FROM #user_list) AND rsvp_status='attending')"
};
目前,我的“event_id”查询中获取了太多结果,我目前获取了“user_list”查询中存储的每个人的完整事件列表,理想情况下我希望只获取 1每个人的事件,然后对这些结果进行排序。我似乎无法做到这一点,使用 LIMIT 我总共只得到 1 个结果,但不是针对每个人。
此外,更重要的是,我只希望“user_name”查询中的每个事件有一个结果,目前我有时会得到多个参加同一事件的成员,这会导致问题,因为我无法匹配用户名收到结果后,将显示相应的事件。我还注意到,如果同一个用户要 如果“event_id”中包含两个不同的事件,则结果中只有一个其名称实例,这也是不可取的。
目前,一旦获得“event_id”结果,我就会进行 20 个 API 调用,然后对返回的数据进行排序,这确实减慢了我的应用程序的速度。
谁能建议我如何实现我想要的,从而优化查询?
抱歉发了这么长的帖子,但这几天来我的乳头一直很不舒服!
谢谢
I'm trying to get my head around whether it would be possible to do something with an FQL multi-query rather than multiple API calls.
Here is my code:
var queries : Object = {
"user_list":"SELECT uid2 FROM friend WHERE uid1 = "+uid
,"event_id":"SELECT eid, start_time, end_time, location, pic, name FROM event
WHERE eid IN (SELECT eid FROM event_member
WHERE uid IN (SELECT uid2 FROM #user_list)
AND rsvp_status='attending') AND start_time > " + nowSecs + "
AND start_time < " + (nowSecs + 2500000) + " ORDER BY start_time ASC LIMIT 20"
"user_name":"SELECT name FROM user
WHERE uid IN (SELECT uid FROM event_member
WHERE eid IN (SELECT eid FROM #event_id)
AND uid IN (SELECT uid2 FROM #user_list) AND rsvp_status='attending')"
};
At the moment there are too many results being fetched in my 'event_id' query, I currently get the full list of events for each person stored in the 'user_list' query, which I would ideally like to only get 1 event for each person, and then sort those results. I can't seem to do this, using LIMIT I only get 1 result back in total, but not for each person.
Additionally, and more importantly, I only want one result per event in the 'user_name' query, at the moment I sometimes get multiple members who are attending the same event, and this causes problems as I have no way of matching the user names up with their corresponding event once the results are received. I have also noticed that if the same user is going to
two different events contained in 'event_id' there is only one instance of their name in the result, which is also undesirable.
At the moment I am making 20 API calls once I have the 'event_id' results and then sorting the data returned, which is really slowing down my app.
Can anyone suggest how I could achieve what I want, and thus optimise the queries please?
Sorry for the long post, but this has been getting on my tits for days!
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我在阅读中了解到的内容,您想要获得:
这与提出的问题非常相似 此处,但他要为每个项目查找 2 个结果,而您只搜索一个。
From what I can tell in reading through, you want to get:
This is very similar to the problem presented here, with the exception that he's going after 2 results for each item and you're searching for only one.