$threshold=qa_opt('max_copy_user_updates');// if this many users subscribe to it, create a shared stream
// Add in the favorite for this user, unshared events at first (will be switched later if appropriate)
// Add in the favorite for this user, unshared events at first (will be switched later if appropriate)
...
@@ -121,7 +124,7 @@
...
@@ -121,7 +124,7 @@
// See whether this entity already has another favoriter who uses its shared event stream
// See whether this entity already has another favoriter who uses its shared event stream
$useshared=qa_db_read_one_value(qa_db_query_sub(
$useshared=qa_db_read_one_value(qa_db_query_sub(
'SELECT COUNT(*) FROM ^userfavorites WHERE entitytype=$ AND entityid=# AND nouserevents>0 LIMIT 1',
'SELECT COUNT(*) FROM ^userfavorites WHERE entitytype=$ AND entityid=# AND nouserevents>0 LIMIT 1',
$entitytype,$entityid
$entitytype,$entityid
));
));
...
@@ -129,12 +132,12 @@
...
@@ -129,12 +132,12 @@
// If not, check whether it's time to switch it over to a shared stream
// If not, check whether it's time to switch it over to a shared stream
if(!$useshared){
if(!$useshared){
$favoriters=qa_db_read_one_value(qa_db_query_sub(
$favoriters=qa_db_read_one_value(qa_db_query_sub(
'SELECT COUNT(*) FROM ^userfavorites WHERE entitytype=$ AND entityid=# LIMIT #',
'SELECT COUNT(*) FROM ^userfavorites WHERE entitytype=$ AND entityid=# LIMIT #',
$entitytype,$entityid,$threshold
$entitytype,$entityid,$threshold
));
));
$useshared=($favoriters>=$threshold);
$useshared=($favoriters>=$threshold);
}
}
// If we're going to use the shared stream...
// If we're going to use the shared stream...
...
@@ -143,16 +146,16 @@
...
@@ -143,16 +146,16 @@
// ... for all the people for whom we're switching this to a shared stream, find the highest number of other shared streams they have
// ... for all the people for whom we're switching this to a shared stream, find the highest number of other shared streams they have
$maxshared=qa_db_read_one_value(qa_db_query_sub(
$maxshared=qa_db_read_one_value(qa_db_query_sub(
'SELECT MAX(c) FROM (SELECT COUNT(*) AS c FROM ^userfavorites AS shared JOIN ^userfavorites AS unshared '.
'SELECT MAX(c) FROM (SELECT COUNT(*) AS c FROM ^userfavorites AS shared JOIN ^userfavorites AS unshared '.
'WHERE shared.userid=unshared.userid AND shared.nouserevents>0 AND unshared.entitytype=$ AND unshared.entityid=# AND unshared.nouserevents=0 GROUP BY shared.userid) y',
'WHERE shared.userid=unshared.userid AND shared.nouserevents>0 AND unshared.entitytype=$ AND unshared.entityid=# AND unshared.nouserevents=0 GROUP BY shared.userid) y',
$entitytype,$entityid
$entitytype,$entityid
));
));
// ... if this number is greater than our current 'max_copy_user_updates' threshold, increase that threshold (see long comment above)
// ... if this number is greater than our current 'max_copy_user_updates' threshold, increase that threshold (see long comment above)
if(($maxshared+1)>$threshold)
if(($maxshared+1)>$threshold)
qa_opt('max_copy_user_updates',$maxshared+1);
qa_opt('max_copy_user_updates',$maxshared+1);
// ... now switch all unshared favoriters (including this new one) over to be shared
// ... now switch all unshared favoriters (including this new one) over to be shared
...
@@ -161,16 +164,16 @@
...
@@ -161,16 +164,16 @@
$entitytype,$entityid
$entitytype,$entityid
);
);
}else{
// Otherwise if we're going to record this in user-specific streams ...
// Otherwise if we're going to record this in user-specific streams ...
}else{
require_onceQA_INCLUDE_DIR.'db/events.php';
require_onceQA_INCLUDE_DIR.'db/events.php';
// ... copy across recent events from the shared stream
// ... copy across recent events from the shared stream
$query="UPDATE ^posts AS x, (SELECT parents.postid, parents.created AS qcreated, COALESCE(MAX(children.created), parents.created) as acreated, COUNT(children.postid) AS acount, parents.netvotes, parents.views FROM ^posts AS parents LEFT JOIN ^posts AS children ON parents.postid=children.parentid AND children.type='A' WHERE parents.postid>=# AND parents.postid<=# AND LEFT(parents.type, 1)='Q' GROUP BY postid) AS a SET x.hotness=(".
$query="UPDATE ^posts AS x, (SELECT parents.postid, parents.created AS qcreated, COALESCE(MAX(children.created), parents.created) as acreated, COUNT(children.postid) AS acount, parents.netvotes, parents.views FROM ^posts AS parents LEFT JOIN ^posts AS children ON parents.postid=children.parentid AND children.type='A' WHERE parents.postid>=# AND parents.postid<=# AND LEFT(parents.type, 1)='Q' GROUP BY postid) AS a SET x.hotness=(".
'((TO_DAYS(a.qcreated)-734138)*86400.0+TIME_TO_SEC(a.qcreated))*# + '.// zero-point is Jan 1, 2010
'((TO_DAYS(a.qcreated)-734138)*86400.0+TIME_TO_SEC(a.qcreated))*# + '.// zero-point is Jan 1, 2010
// delete PM only if both sender and receiver have hidden it
// delete PM only if both sender and receiver have hidden it
$clause=$public?'':' AND fromhidden=1 AND tohidden=1';
$clause=$public?'':' AND fromhidden=1 AND tohidden=1';
qa_db_query_sub(
qa_db_query_sub(
'DELETE FROM ^messages WHERE messageid=#'.$clause,
'DELETE FROM ^messages WHERE messageid=#'.$clause,
$messageid
$messageid
);
);
}
}
functionqa_db_user_recount_posts($userid)
/**
/*
* Recalculate the cached count of wall posts for user $userid in the database
Recalculate the cached count of wall posts for user $userid in the database
* @param $userid
*/
*/
{
functionqa_db_user_recount_posts($userid)
if(qa_should_update_counts())
{
if(qa_should_update_counts()){
qa_db_query_sub(
qa_db_query_sub(
"UPDATE ^users AS x, (SELECT COUNT(*) AS wallposts FROM ^messages WHERE touserid=# AND type='PUBLIC') AS a SET x.wallposts=a.wallposts WHERE x.userid=#",
"UPDATE ^users AS x, (SELECT COUNT(*) AS wallposts FROM ^messages WHERE touserid=# AND type='PUBLIC') AS a SET x.wallposts=a.wallposts WHERE x.userid=#",
$userid,$userid
$userid,$userid
);
);
}
}
}
/*
Omit PHP closing tag to help avoid accidental output
'formula'=>"COUNT(*) AS aselecteds FROM ^posts AS userid_src JOIN ^posts AS questions ON questions.selchildid=userid_src.postid WHERE userid_src.userid~ AND userid_src.type='A' AND NOT (questions.userid<=>userid_src.userid)",
'formula'=>"COUNT(*) AS aselecteds FROM ^posts AS userid_src JOIN ^posts AS questions ON questions.selchildid=userid_src.postid WHERE userid_src.userid~ AND userid_src.type='A' AND NOT (questions.userid<=>userid_src.userid)",
'formula'=>"COUNT(*) AS qupvotes FROM ^uservotes AS userid_src JOIN ^posts ON userid_src.postid=^posts.postid WHERE userid_src.userid~ AND LEFT(^posts.type, 1)='Q' AND userid_src.vote>0",
'formula'=>"COUNT(*) AS qupvotes FROM ^uservotes AS userid_src JOIN ^posts ON userid_src.postid=^posts.postid WHERE userid_src.userid~ AND LEFT(^posts.type, 1)='Q' AND userid_src.vote>0",
'formula'=>"COUNT(*) AS qdownvotes FROM ^uservotes AS userid_src JOIN ^posts ON userid_src.postid=^posts.postid WHERE userid_src.userid~ AND LEFT(^posts.type, 1)='Q' AND userid_src.vote<0",
'formula'=>"COUNT(*) AS qdownvotes FROM ^uservotes AS userid_src JOIN ^posts ON userid_src.postid=^posts.postid WHERE userid_src.userid~ AND LEFT(^posts.type, 1)='Q' AND userid_src.vote<0",
'formula'=>"COUNT(*) AS aupvotes FROM ^uservotes AS userid_src JOIN ^posts ON userid_src.postid=^posts.postid WHERE userid_src.userid~ AND LEFT(^posts.type, 1)='A' AND userid_src.vote>0",
'formula'=>"COUNT(*) AS aupvotes FROM ^uservotes AS userid_src JOIN ^posts ON userid_src.postid=^posts.postid WHERE userid_src.userid~ AND LEFT(^posts.type, 1)='A' AND userid_src.vote>0",
'formula'=>"COUNT(*) AS adownvotes FROM ^uservotes AS userid_src JOIN ^posts ON userid_src.postid=^posts.postid WHERE userid_src.userid~ AND LEFT(^posts.type, 1)='A' AND userid_src.vote<0",
'formula'=>"COUNT(*) AS adownvotes FROM ^uservotes AS userid_src JOIN ^posts ON userid_src.postid=^posts.postid WHERE userid_src.userid~ AND LEFT(^posts.type, 1)='A' AND userid_src.vote<0",