dtgj8529 2012-09-21 14:09
浏览 31
已采纳

在PHP会话期间存储用户的“跟随”

I have a simple followers/following system set up within my app.

What would be the best way to store a complete array of 'users following' during a session so that I don't have to query the database multiple times throughout.

To clarify: When a user logs in once they have been authorized I query the database, get a full list of users that the logged in user is following and ultimately store it as a JavaScript variable. This way throughout the site, as the user navigates around I can constantly check the following status against any other user they may come across.

This query is only performed once when the user loads the full page, while navigating around it is not repeated.

This works well for javascript generated content i.e user hovercards etc...

However I would like to store this array (of only userid's) in PHP itself so that I can prevent further queries to the following table while generating content server side that requires a 'follower/following' check to be performed.

What would be the best way to do this?

Please bare in mind that the results are cached in memcached but if I can avoid any lookups at all and have a consistent array to check against that would be great.

Thanks in advance

  • 写回答

3条回答 默认 最新

  • douxian1923 2012-09-21 14:14
    关注

    So let me get this right, you want to store this list so it isn't queried on each page?

    First I would recommend you only perform this query on pages that need this data and second I would say that on these pages you don't try this.

    Imagine a user stops following or starts following. Some complex cache calculator or event bubbler programmed into your own PHP app to purge the foreign session of data (which is bad, the user has access to data that is not their own, a session infact) could be tiedious with security and performance.

    The better thing to do is to perform the query again for each new page. This would be much easier, probably more performant and wouldn't be micro-optimising.

    Edit

    If you are picking out 10k rows on one page then you might be doing something wrong. You might be looking at it from the wrong perspective.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)