作者:叫我小小小火枪的天空_603 | 来源:互联网 | 2023-05-18 01:32
Imbuildingasitewithdjangothatletsusersmovecontentaroundbetweenabunchofphotoservice
I'm building a site with django that lets users move content around between a bunch of photo services. As you can imagine the application does a lot of api hits.
我正在使用django构建一个网站,允许用户在一堆照片服务之间移动内容。你可以想象这个应用程序做了很多api命中。
for example: user connects picasa, flickr, photobucket, and facebook to their account. Now we need to pull content from 4 different apis to keep this users data up to date.
例如:用户将picasa,flickr,photobucket和facebook连接到他们的帐户。现在我们需要从4个不同的api中提取内容,以使这些用户数据保持最新状态。
right now I have a a function that updates each api and I run them all simultaneously via threading. (all the api's that are not enabled return false on the second line, no it's not much overhead to run them all).
现在我有一个更新每个api的函数,我通过线程同时运行它们。 (所有未启用的api都会在第二行返回false,不是没有太大的开销来运行它们)。
Here is my question:
What is the best strategy for keeping content up to date using these APIs?
使用这些API保持内容最新的最佳策略是什么?
I have two ideas that might work:
我有两个可能有用的想法:
Update the apis periodically (like a cron job) and whatever we have at the time is what the user gets.
定期更新api(如cron作业),当时我们拥有的是用户获得的内容。
benefits:
- It's easy and simple to implement.
实施简单易行。
- We'll always have pretty good data when a user loads their first page.
当用户加载他们的第一页时,我们总是会有非常好的数据。
pitfalls:
- we have to do api hits all the time for users that are not active, which wastes a lot of bandwidth
我们必须一直为那些不活跃的用户做api命中,这会浪费很多带宽
- It will probably make the api providers unhappy
它可能会使api提供商不高兴
Trigger the updates when the user logs in (on a pageload)
用户登录时触发更新(在页面加载上)
benefits:
- we save a bunch of bandwidth and run less risk of pissing off the api providers
我们节省了大量带宽,降低了api提供商的压力
- doesn't require NEARLY the amount of resources on our servers
我们的服务器上几乎不需要大量的资源
pitfalls:
- we either have to do the update asynchronously (and won't have anything on first login) or...
我们要么必须异步进行更新(并且首次登录时不会有任何内容)或者......
- the first page will take a very long time to load because we're getting all the api data (I've measured 26 seconds this way)
第一页需要很长时间才能加载,因为我们正在获取所有api数据(我用这种方式测量了26秒)
edit: the design is very light, the design has only two images, an external css file, and two external Javascript files.
编辑:设计很轻,设计只有两个图像,一个外部css文件和两个外部Javascript文件。
Also, the 26 seconds number comes from the firebug network monitor running on a machine which was on the same LAN as the server
此外,26秒的数字来自在与服务器位于同一LAN上的计算机上运行的firebug网络监视器
1 个解决方案