简体   繁体   English

Facebook顶级共享URL,按用户间隔更新,MySQL选择更新

[英]Facebook top shared urls, update by user with interval and mysql select update

I know the title is complicated, but i was looking for some advise on this and found nothing. 我知道标题很复杂,但是我一直在寻找一些建议,却一无所获。

Just want to ask if i'm thinking the right way. 只想问我是否在想正确的方法。

I need to make a top facebook shared page with about 10 items or so for my website items (images, articles etc.) 我需要在顶部的Facebook共享页面上放置大约10个左右的网站项目(图片,文章等)。

And this is simple, i will just get the share count from facebook graph api and update in database, i don't want to make it in some ajax call based on fb share, it could be misused. 这很简单,我只会从facebook graph api获取共享计数并在数据库中更新,我不想在基于fb共享的ajax调用中进行共享,这可能会被滥用。

Every item has datetime of last update, create date and likes fields in database. 每个项目都有上次更新的日期时间,创建日期以及喜欢数据库中的字段。

I will also need to make top shared url in 24h, 7 days and month so the idea is simple: 我还需要在24小时,7天和一个月内制作顶级共享网址,这样的想法很简单:

  1. User views an item, every 10 minutes the shared count is obtained from fb graph api for this url and updated in database, database also stores last update time. 用户查看一个项目,每10分钟从fb图形api获取此URL的共享计数,并在数据库中更新,数据库还存储最近的更新时间。
  2. Every time user is viewing the item, the site checks last update datetime, if it is more than 10 minutes it makes fb api call and updates. 每次用户查看项目时,网站都会检查上次更新日期时间,如果超过10分钟,则会进行fb api调用和更新。 It is every 10 minutes to lower fb api calls. 每隔10分钟就会降低fb api调用。

This basically works, but there is a problem - concurrency. 这基本上可以工作,但是有一个问题-并发。

When the item is selected then in php i check if last update was 10 minutes ago or more, and only then i make a call to fb api and then update the share count (if bigger than current) and rest of data, because a remote call is costly and to lower fb api usage. 当选择该项目时,然后在php中检查是否最近的更新是10分钟前或更长时间,然后才调用fb api,然后更新共享计数(如果大于当前值)和其他数据,因为远程调用成本很高,并且降低了FB API的使用率。

So, till users view items, they are updated, but the update is depending on select and i can't make it in one SQL statement because of time check and the remote call, so one user can enter and then another, both after 10 minutes and then there is a chance it will call fb api many times, and update many times, the more users, the more calls and updates and THIS IS NOT GOOD. 因此,直到用户查看项目,它们才会更新,但是更新取决于select并且由于时间检查和远程调用,我无法在一个SQL语句中进行更新,因此一个用户可以输入,然后另一个用户输入,都在10点之后分钟,然后有机会将fb api多次调用,并多次更新,用户越多,调用和更新就越多,这不是很好。

Any advise how to fix this? 任何建议如何解决这个问题? I'm doing it right? 我做对了吗? Maybe there is a better way? 也许有更好的方法?

You can either decouple the api check from user interaction completely and have a separate scheduled process collect the facebook data every 10 minutes, regardless of users 您既可以将api检查与用户交互完全脱钩,也可以有一个独立的计划进程每10分钟收集一次Facebook数据,无论用户如何

Or, if you'd rather pursue this event-driven model, then you need to look at using a 'mutex'. 或者,如果您希望采用这种事件驱动的模型,则需要考虑使用“互斥量”。 Basically, set a flag somewhere (in a file, or a database, etc) which indicates that a checking process is currently running, and not to run another one. 基本上,在某个位置(在文件或数据库等中)设置一个标志,该标志指示当前正在运行检查进程,而不运行另一个进程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM