我正在创建一个社交媒体网站,我试图找到最有效/最省时的方式来加载你所有人的所有最新帖子#34 ;订阅"至。我认为我这样做的方式是低技术,如果你遵循一定的目标可能需要一段时间"很多"粉丝数量。我试图通过将我从SQL结果中获得的关注者的初始列表保存到会话中来加快速度,这样就不必再次重新加载,除非有人阻止了您或者您没有关注某人。
$ que_posts [6]下面加载了你所关注的所有人,并且每个人都有一个相应的UNION子句,它将它连接到SQL查询。
请不要发布我如何使用程序样式,我有字符编码和适当的字符过滤器设置。
sg_permissions和posts
的架构/表|------
|Column|Type|Null|Default
|------
|access_type|varchar(30)|No|
|towhom|varchar(30)|No|
|date_g|date|No|
|granted_by|varchar(35)|No|
|//**sgp_id**//|int(11)|No|
== Dumping data for table sg_permissions
|friend snowglobe|nolvorite|2014-12-16|nerd|1
|friend snowglobe|nerd|2014-12-17|nolvorite|2
帖子
===Database captiv8
== Table structure for table posts
|------
|Column|Type|Null|Default
|------
|content|varchar(15000)|Yes|NULL
|cnttype|int(11)|No|
|msgtype|char(20)|Yes|NULL
|forwhom|text|No|
|parent|int(11)|No|
|//**postid**//|int(11)|No|
|stamptime|timestamp|No|CURRENT_TIMESTAMP
|bywhom|text|No|
|title|varchar(150)|Yes|NULL
|thread_nick|varchar(50)|Yes|NULL
|topic_hash|varchar(10)|Yes|NULL
|settings|int(11)|No|1
|thread_id|int(11)|Yes|NULL
|level|int(11)|Yes|NULL
|upvotes|int(11)|No|1
|downvotes|int(11)|No|0
|post_type|int(11)|No|0
== Dumping data for table posts
|Reply to this comment... Ergo, comment on this comment.|2|NULL|n-a|28|35|2014-11-28 15:19:01|nolvorite|Comments|Comments|acf8ac4cf4|1|19|NULL|1|0|0
|another one|2|NULL|n-a|33|36|2014-11-29 18:51:41|nolvorite|Comments|Comments|383780840c|1|19|NULL|1|0|0
|last comment generation to boot?|2|NULL|n-a|36|37|2014-11-29 22:50:18|nolvorite|Comments|Comments|1974971f18|1|19|NULL|1|0|0
|test last comment generation?|2|NULL|n-a|36|38|2014-11-29 22:51:19|nolvorite|Comments|Comments|0aadae2602|1|19|NULL|1|0|0
|test once and never again|2|NULL|n-a|36|39|2014-11-30 02:33:37|nolvorite|Comments|Comments|6a334ce691|1|19|NULL|1|0|0
实际代码
$zoom = "SELECT * FROM posts WHERE bywhom='$logged_dt[username]' AND cnttype=1";
//have to find an efficient way to load the most recent posts
//among other ways of assortment
//i'm gonna have to put it in a session
//clear it when the person follows new people/the person gets blocked
//that way it's only going to have to search once as long as those things don't happen
if(!isset($_SESSION['content_pool'])){
$que_posts[6] = mysqli_query($db_main, "SELECT * FROM sg_permissions WHERE towhom='$_MONITORED[login_q]'");
$xn = 0;
while($que_others_posts = mysqli_fetch_assoc($que_posts[6])){ $xn++;
//sort em'
$_SESSION['content_pool'][preg_replace("#[ :]+#","",$que_others_posts['access_type'])] = array($xn => $que_others_posts);
}
}
for($i = 1;$i <= count($_SESSION['content_pool']);$i++){
foreach($_SESSION['content_pool']['friendsnowglobe'] as $friends_feed){
$zoom .= " UNION SELECT * FROM posts WHERE bywhom='".$friends_feed['granted_by']."' AND cnttype=1"; //I have a feeling this is horribly inefficient
} }
var_dump($_SESSION['content_pool']);
$que_posts[0] = mysqli_query($db_main, $zoom . " ORDER by stamptime DESC LIMIT 0,75");
while($que_own = mysqli_fetch_assoc($que_posts[0])){
//begin posts