slow progress removing bitfields on item table

This commit is contained in:
friendica 2015-01-21 16:06:25 -08:00
parent 51848c6190
commit 29436081a8
20 changed files with 154 additions and 177 deletions

View File

@ -536,7 +536,7 @@ define ( 'ITEM_PENDING_REMOVE', 0x0800); // deleted, notification period has
* Item Flags
*/
define ( 'ITEM_ORIGIN', 0x0001);
//define ( 'ITEM_ORIGIN', 0x0001);
define ( 'ITEM_UNSEEN', 0x0002);
define ( 'ITEM_STARRED', 0x0004);
define ( 'ITEM_UPLINK', 0x0008);

View File

@ -88,7 +88,10 @@ function refimport_content(&$a) {
$arr['author_xchan'] = $channel['channel_hash'];
$arr['owner_xchan'] = $channel['channel_hash'];
$arr['app'] = REFLECT_BLOGNAME;
$arr['item_flags'] = ITEM_ORIGIN|ITEM_WALL|ITEM_THREAD_TOP;
$arr['item_origin'] = 1;
$arr['item_wall'] = 1;
$arr['item_thread_top'] = 1;
$arr['verb'] = ACTIVITY_POST;
// this is an assumption
@ -256,7 +259,8 @@ function reflect_comment_store($channel,$post,$comment,$user) {
$arr['edited'] = $comment['created'];
$arr['author_xchan'] = $hash;
$arr['owner_xchan'] = $channel['channel_hash'];
$arr['item_flags'] = ITEM_ORIGIN|ITEM_WALL;
$arr['item_origin'] = 1;
$arr['item_wall'] = 1;
$arr['verb'] = ACTIVITY_POST;
$arr['comment_policy'] = 'contacts';

View File

@ -21,7 +21,10 @@ function profile_activity($changed, $value) {
$arr['uid'] = local_user();
$arr['aid'] = $self['channel_account_id'];
$arr['owner_xchan'] = $arr['author_xchan'] = $self['xchan_hash'];
$arr['item_flags'] = ITEM_WALL|ITEM_ORIGIN|ITEM_THREAD_TOP;
$arr['item_wall'] = 1;
$arr['item_origin'] = 1;
$arr['item_thread_top'] = 1;
$arr['verb'] = ACTIVITY_UPDATE;
$arr['obj_type'] = ACTIVITY_OBJ_PROFILE;

View File

@ -954,7 +954,9 @@ function file_activity($channel_id, $hash, $allow_cid, $allow_gid, $deny_cid, $d
$mid = item_message_id();
$item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_UNSEEN;
$arr['item_wall'] = 1;
$arr['item_origin'] = 1;
$arr['item_unseen'] = 1;
if($action == 'post') {
//check if activity item exists
@ -975,7 +977,6 @@ function file_activity($channel_id, $hash, $allow_cid, $allow_gid, $deny_cid, $d
$arr['uid'] = $channel_id;
$arr['mid'] = $dmid;
$arr['parent_mid'] = $dmid;
$arr['item_flags'] = $item_flags;
$arr['author_xchan'] = $poster['xchan_hash'];
$arr['owner_xchan'] = $poster['xchan_hash'];
$arr['title'] = '';
@ -1016,7 +1017,9 @@ function file_activity($channel_id, $hash, $allow_cid, $allow_gid, $deny_cid, $d
$arr['uid'] = $channel_id;
$arr['mid'] = $mid;
$arr['parent_mid'] = $mid;
$arr['item_flags'] = $item_flags;
$arr['item_wall'] = 1;
$arr['item_origin'] = 1;
$arr['item_unseen'] = 1;
$arr['author_xchan'] = $poster['xchan_hash'];
$arr['owner_xchan'] = $poster['xchan_hash'];
$arr['title'] = '';

View File

@ -271,22 +271,6 @@ function bb2diaspora_itemwallwall(&$item) {
. $item['body'];
}
// We have to do something similar for wall-to-wall comments. ITEM_WALL|ITEM_ORIGIN indicates that it was posted on this site.
// Regular matrix comments may have one of these bits set, but not both.
// Update: this is getting triggered way too often and unnecessarily. Commenting out until we find a better solution.
// It's not an easy problem. For now we'll live with the mis-attributions, as wall to wall comments are much less frequent
// than wall-to-wall posts.
// if(($item['mid'] != $item['parent_mid']) && ($item['author_xchan'] != $item['owner_xchan']) && (($item['item_flags'] & (ITEM_WALL|ITEM_ORIGIN)) == (ITEM_WALL|ITEM_ORIGIN)) && (is_array($item['author'])) && $item['author']['xchan_url'] && $item['author']['xchan_name'] && $item['author']['xchan_photo_m']) {
// logger('bb2diaspora_itemwallwall: wall to wall comment',LOGGER_DEBUG);
// post will come across with the owner's identity. Throw a preamble onto the post to indicate the true author.
// $item['body'] = "\n\n"
// . '[img]' . $item['author']['xchan_photo_m'] . '[/img]'
// . '[url=' . $item['author']['xchan_url'] . ']' . $item['author']['xchan_name'] . '[/url]' . "\n\n"
// . $item['body'];
// }
// $item['author'] might cause a surprise further down the line if it wasn't expected to be here.
if(! $author_exists)

View File

@ -1414,7 +1414,7 @@ function diaspora_comment($importer,$xml,$msg) {
if($result && $result['success'])
$message_id = $result['item_id'];
if(($parent_item['item_flags'] & ITEM_ORIGIN) && (! $parent_author_signature)) {
if(intval($parent_item['item_origin']) && (! $parent_author_signature)) {
// if the message isn't already being relayed, notify others
// the existence of parent_author_signature means the parent_author or owner
// is already relaying.
@ -1996,7 +1996,7 @@ function diaspora_like($importer,$xml,$msg) {
// the existence of parent_author_signature means the parent_author or owner
// is already relaying. The parent_item['origin'] indicates the message was created on our system
if(($parent_item['item_flags'] & ITEM_ORIGIN) && (! $parent_author_signature))
if(intval($parent_item['item_origin']) && (! $parent_author_signature))
proc_run('php','include/notifier.php','comment-import',$message_id);
return;
@ -2105,19 +2105,12 @@ function diaspora_signed_retraction($importer,$xml,$msg) {
$r[0]['parent']
);
if($p) {
if(($p[0]['item_flags'] & ITEM_ORIGIN) && (! $parent_author_signature)) {
// FIXME so we can relay this
// q("insert into sign (`retract_iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
// $r[0]['id'],
// dbesc($signed_data),
// dbesc($sig),
// dbesc($diaspora_handle)
// );
if(intval($p[0]['item_origin']) && (! $parent_author_signature)) {
// the existence of parent_author_signature would have meant the parent_author or owner
// is already relaying.
logger('diaspora_signed_retraction: relaying relayable_retraction');
logger('diaspora_signed_retraction: relaying relayable_retraction');
proc_run('php','include/notifier.php','drop',$r[0]['id']);
}
}

View File

@ -457,19 +457,20 @@ function event_store_item($arr,$event) {
$private = (($arr['allow_cid'] || $arr['allow_gid'] || $arr['deny_cid'] || $arr['deny_gid']) ? 1 : 0);
$item_wall = 0;
$item_origin = 0;
$item_thread_top = 0;
if($item) {
$item_arr['id'] = $item['id'];
}
else {
$wall = (($z[0]['channel_hash'] == $event['event_xchan']) ? true : false);
$item_flags = ITEM_THREAD_TOP;
$item_thread_top = 1;
if($wall) {
$item_flags |= ITEM_WALL;
$item_flags |= ITEM_ORIGIN;
$item_wall = 1;
$item_origin = 1;
}
$item_arr['item_flags'] = $item_flags;
}
@ -492,6 +493,9 @@ function event_store_item($arr,$event) {
$item_arr['deny_gid'] = $arr['deny_gid'];
$item_arr['item_private'] = $private;
$item_arr['verb'] = ACTIVITY_POST;
$item_arr['item_wall'] = $item_wall;
$item_arr['item_origin'] = $item_origin;
$item_arr['item_thread_top'] = $item_thread_top;;
if(array_key_exists('term',$arr))
@ -499,9 +503,7 @@ function event_store_item($arr,$event) {
$item_arr['resource_type'] = 'event';
$item_arr['resource_id'] = $event['event_hash'];
$item_arr['obj_type'] = ACTIVITY_OBJ_EVENT;
$item_arr['body'] = $prefix . format_event_bbcode($arr);
// if it's local send the permalink to the channel page.

View File

@ -93,26 +93,6 @@ function externals_run($argv, $argc){
$results = process_delivery(array('hash' => 'undefined'), get_item_elements($message),
array(array('hash' => $sys['xchan_hash'])), false, true);
$total ++;
// $z = q("select id from item where mid = '%s' and uid = %d limit 1",
// dbesc($message['message_id']),
// intval($sys['channel_id'])
// );
$z = null;
if($z) {
$flag_bits = ITEM_WALL|ITEM_ORIGIN|ITEM_UPLINK;
// preserve the source
$r = q("update item set source_xchan = owner_xchan where id = %d",
intval($z[0]['id'])
);
$r = q("update item set item_flags = ( item_flags | %d ), owner_xchan = '%s'
where id = %d",
intval($flag_bits),
dbesc($sys['xchan_hash']),
intval($z[0]['id'])
);
}
}
logger('externals: import_public_posts: ' . $total . ' messages imported', LOGGER_DEBUG);
}

View File

@ -364,13 +364,12 @@ function post_activity_item($arr) {
if((($arr['parent']) && $arr['parent'] != $arr['id']) || (($arr['parent_mid']) && $arr['parent_mid'] != $arr['mid']))
$is_comment = true;
if(! x($arr,'item_flags')) {
if($is_comment)
$arr['item_flags'] = ITEM_ORIGIN;
else
$arr['item_flags'] = ITEM_ORIGIN | ITEM_WALL | ITEM_THREAD_TOP;
}
if(! array_key_exists('item_origin',$arr))
$arr['item_origin'] = 1;
if(! array_key_exists('item_wall',$arr) && (! $is_comment))
$arr['item_wall'] = 1;
if(! array_key_exists('item_thread_top',$arr) && (! $is_comment))
$arr['item_thread_top'] = 1;
$channel = get_app()->get_channel();
$observer = get_app()->get_observer();
@ -2917,10 +2916,7 @@ function tag_deliver($uid,$item_id) {
// prevent delivery looping - only proceed
// if the message originated elsewhere and is a top-level post
if(($item['item_flags'] & ITEM_WALL)
|| ($item['item_flags'] & ITEM_ORIGIN)
|| (!($item['item_flags'] & ITEM_THREAD_TOP))
|| ($item['id'] != $item['parent'])) {
if(intval($item['item_wall']) || intval($item['item_origin']) || (! intval($item['item_thread_top'])) || ($item['id'] != $item['parent'])) {
logger('tag_deliver: item was local or a comment. rejected.');
return;
}
@ -3039,7 +3035,10 @@ function start_delivery_chain($channel,$item,$item_id,$parent) {
if((! $private) && $new_public_policy)
$private = 1;
$flag_bits = $item['item_flags'] | ITEM_WALL|ITEM_ORIGIN;
$item_wall = 1;
$item_origin = 1;
$flag_bits = $item['item_flags'];
// unset the nocomment bit if it's there.
@ -3087,7 +3086,7 @@ function start_delivery_chain($channel,$item,$item_id,$parent) {
}
$r = q("update item set item_flags = %d, owner_xchan = '%s', allow_cid = '%s', allow_gid = '%s',
deny_cid = '%s', deny_gid = '%s', item_private = %d, public_policy = '%s', comment_policy = '%s', title = '%s', body = '%s' where id = %d",
deny_cid = '%s', deny_gid = '%s', item_private = %d, public_policy = '%s', comment_policy = '%s', title = '%s', body = '%s', item_wall = %d, item_origin = %d where id = %d",
intval($flag_bits),
dbesc($channel['channel_hash']),
dbesc($channel['channel_allow_cid']),
@ -3099,6 +3098,8 @@ function start_delivery_chain($channel,$item,$item_id,$parent) {
dbesc(map_scope($channel['channel_w_comment'])),
dbesc($title),
dbesc($body),
intval($item_wall),
$intval($item_origin),
intval($item_id)
);

View File

@ -362,7 +362,7 @@ function notifier_run($argv, $argc){
$encoded_item = encode_item($target_item);
$relay_to_owner = (((! $top_level_post) && ($target_item['item_flags'] & ITEM_ORIGIN)) ? true : false);
$relay_to_owner = (((! $top_level_post) && (intval($target_item['item_origin']))) ? true : false);
$uplink = false;
@ -371,7 +371,6 @@ function notifier_run($argv, $argc){
logger('notifier: relay_to_owner: ' . (($relay_to_owner) ? 'true' : 'false'), LOGGER_DATA);
logger('notifier: top_level_post: ' . (($top_level_post) ? 'true' : 'false'), LOGGER_DATA);
logger('notifier: target_item_flags: ' . $target_item['item_flags'] . ' ' . (($target_item['item_flags'] & ITEM_ORIGIN ) ? 'true' : 'false'), LOGGER_DATA);
// tag_deliver'd post which needs to be sent back to the original author

View File

@ -225,7 +225,6 @@ function photo_upload($channel, $observer, $args) {
// Create item container
$item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_THREAD_TOP;
$item_restrict = (($visible) ? ITEM_VISIBLE : ITEM_HIDDEN);
$title = '';
$mid = item_message_id();
@ -248,7 +247,9 @@ function photo_upload($channel, $observer, $args) {
$arr['deny_cid'] = $str_contact_deny;
$arr['deny_gid'] = $str_group_deny;
$arr['verb'] = ACTIVITY_POST;
$arr['item_wall'] = 1;
$arr['item_origin'] = 1;
$arr['item_thread_top'] = 1;
$arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid'];
if ($width_x_height)
@ -431,7 +432,6 @@ function photos_create_item($channel, $creator_hash, $photo, $visible = false) {
// Create item container
$item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_THREAD_TOP;
$item_restrict = (($visible) ? ITEM_VISIBLE : ITEM_HIDDEN);
$title = '';
@ -443,7 +443,9 @@ function photos_create_item($channel, $creator_hash, $photo, $visible = false) {
$arr['uid'] = $channel['channel_id'];
$arr['mid'] = $mid;
$arr['parent_mid'] = $mid;
$arr['item_flags'] = $item_flags;
$arr['item_wall'] = 1;
$arr['item_origin'] = 1;
$arr['item_thread_top'] = 1;
$arr['item_restrict'] = $item_restrict;
$arr['resource_type'] = 'photo';
$arr['resource_id'] = $photo['resource_id'];

View File

@ -1549,7 +1549,7 @@ function process_delivery($sender,$arr,$deliveries,$relay,$public = false,$reque
$result[] = array($d['hash'],'update ignored',$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']);
// We need this line to ensure wall-to-wall comments are relayed (by falling through to the relay bit),
// and at the same time not relay any other relayable posts more than once, because to do so is very wasteful.
if(! ($r[0]['item_flags'] & ITEM_ORIGIN))
if(! intval($r[0]['item_origin']))
continue;
}
}

View File

@ -186,7 +186,9 @@ function connedit_post(&$a) {
&& (intval(get_pconfig($channel['channel_id'],'system','post_newfriend')))) {
$xarr = array();
$xarr['verb'] = ACTIVITY_FRIEND;
$xarr['item_flags'] = ITEM_WALL|ITEM_ORIGIN|ITEM_THREAD_TOP;
$xarr['item_wall'] = 1;
$xarr['item_origin'] = 1;
$xarr['item_thread_top'] = 1;
$xarr['owner_xchan'] = $xarr['author_xchan'] = $channel['channel_hash'];
$xarr['allow_cid'] = $channel['channel_allow_cid'];
$xarr['allow_gid'] = $channel['channel_allow_gid'];

View File

@ -281,7 +281,7 @@ function item_post(&$a) {
// For comments, We need to additionally look at the parent and see if it's a wall post that originated locally.
if($observer['xchan_name'] != $owner_xchan['xchan_name']) {
if($parent_item && ($parent_item['item_flags'] & (ITEM_WALL|ITEM_ORIGIN)) == (ITEM_WALL|ITEM_ORIGIN)) {
if(($parent_item) && ($parent_item['item_wall'] && $parent_item['item_origin'])) {
$walltowall_comment = true;
$walltowall = true;
}
@ -640,14 +640,10 @@ function item_post(&$a) {
}
}
if(local_user() != $profile_uid)
$item_flags |= ITEM_UNSEEN;
$item_unseen = ((local_user() != $profile_uid) ? 1 : 0);
$item_wall = (($post_type === 'wall' || $post_type === 'wall-comment') ? 1 : 0);
$item_origin = (($origin) ? 1 : 0);
if($post_type === 'wall' || $post_type === 'wall-comment')
$item_flags = $item_flags | ITEM_WALL;
if($origin)
$item_flags = $item_flags | ITEM_ORIGIN;
if($moderated)
$item_restrict = $item_restrict | ITEM_MODERATED;
@ -678,11 +674,9 @@ function item_post(&$a) {
$datarray = array();
if(! $parent) {
$item_flags = $item_flags | ITEM_THREAD_TOP;
}
$item_thead_top = ((! $parent) ? 1 : 0);
if ((! $plink) && ($item_flags & ITEM_THREAD_TOP)) {
if ((! $plink) && ($item_thread_top)) {
$plink = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $mid;
}
@ -717,6 +711,10 @@ function item_post(&$a) {
$datarray['postopts'] = $postopts;
$datarray['item_restrict'] = $item_restrict;
$datarray['item_flags'] = $item_flags;
$datarray['item_unseen'] = $item_unseen;
$datarray['item_wall'] = $item_wall;
$datarray['item_origin'] = $item_origin;
$datarray['item_thread_top'] = $item_thread_top;
$datarray['layout_mid'] = $layout_mid;
$datarray['public_policy'] = $public_policy;
$datarray['comment_policy'] = map_scope($channel['channel_w_comment']);

View File

@ -293,10 +293,12 @@ function like_content(&$a) {
}
$mid = item_message_id();
$arr = array();
if($extended_like) {
$item_flags = ITEM_THREAD_TOP|ITEM_ORIGIN|ITEM_WALL;
$arr['item_thread_top'] = 1;
$arr['item_origin'] = 1;
$arr['item_wall'] = 1;
}
else {
$post_type = (($item['resource_type'] === 'photo') ? t('photo') : t('status'));
@ -329,7 +331,9 @@ function like_content(&$a) {
if(! ($item['item_flags'] & ITEM_THREAD_TOP))
$post_type = 'comment';
$item_flags = ITEM_ORIGIN | ITEM_NOTSHOWN;
$arr['item_origin'] = 1;
$arr['item_notshown'] = 1;
if($item['item_flags'] & ITEM_WALL)
$item_flags |= ITEM_WALL;
@ -361,7 +365,6 @@ function like_content(&$a) {
killme();
$arr = array();
if($extended_like) {
$ulink = '[zrl=' . $ch[0]['xchan_url'] . ']' . $ch[0]['xchan_name'] . '[/zrl]';

View File

@ -61,10 +61,6 @@ function mood_init(&$a) {
$mid = item_message_id();
$action = sprintf( t('%1$s is %2$s','mood'), '[zrl=' . $poster['xchan_url'] . ']' . $poster['xchan_name'] . '[/zrl]' , $verbs[$verb]);
$item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_UNSEEN;
if(! $parent_mid)
$item_flags |= ITEM_THREAD_TOP;
$arr = array();
@ -72,7 +68,6 @@ function mood_init(&$a) {
$arr['uid'] = $uid;
$arr['mid'] = $mid;
$arr['parent_mid'] = (($parent_mid) ? $parent_mid : $mid);
$arr['item_flags'] = $item_flags;
$arr['author_xchan'] = $poster['xchan_hash'];
$arr['owner_xchan'] = (($parent_mid) ? $r[0]['owner_xchan'] : $poster['xchan_hash']);
$arr['title'] = '';
@ -83,8 +78,13 @@ function mood_init(&$a) {
$arr['item_private'] = $private;
$arr['verb'] = $activity;
$arr['body'] = $action;
$arr['item_origin'] = 1;
$arr['item_wall'] = 1;
$arr['item_unseen'] = 1;
if(! $parent_mid)
$item['item_thread_top'] = 1;
if ((! $arr['plink']) && ($arr['item_flags'] & ITEM_THREAD_TOP)) {
if ((! $arr['plink']) && intval($arr['item_thread_top'])) {
$arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid'];
}

View File

@ -87,9 +87,6 @@ function poke_init(&$a) {
$arr = array();
$arr['item_flags'] = ITEM_WALL | ITEM_ORIGIN;
if($parent_item)
$arr['item_flags'] |= ITEM_THREAD_TOP;
$arr['owner_xchan'] = (($parent_item) ? $parent_item['owner_xchan'] : $channel['channel_hash']);
$arr['parent_mid'] = (($parent_mid) ? $parent_mid : $mid);
@ -115,6 +112,13 @@ function poke_init(&$a) {
$arr['object'] = json_encode($obj);
$arr['item_origin'] = 1;
$arr['item_wall'] = 1;
$arr['item_unseen'] = 1;
if(! $parent_item)
$item['item_thread_top'] = 1;
post_activity_item($arr);
return;

View File

@ -102,23 +102,22 @@ function subthread_content(&$a) {
$bodyverb = t('%1$s is following %2$s\'s %3$s');
$item_flags = ITEM_ORIGIN | ITEM_NOTSHOWN;
if($item['item_flags'] & ITEM_WALL)
$item_flags |= ITEM_WALL;
$arr = array();
$arr['mid'] = $mid;
$arr['aid'] = $owner_aid;
$arr['uid'] = $owner_uid;
$arr['item_flags'] = $item_flags;
$arr['parent'] = $item['id'];
$arr['parent_mid'] = $item['mid'];
$arr['thr_parent'] = $item['mid'];
$arr['owner_xchan'] = $thread_owner['xchan_hash'];
$arr['author_xchan'] = $observer['xchan_hash'];
$arr['item_origin'] = 1;
$arr['item_notshown'] = 1;
if(intval($item['item_wall']))
$arr['item_wall'] = 1;
else
$arr['item_wall'] = 0;
$ulink = '[zrl=' . $item_author['xchan_url'] . ']' . $item_author['xchan_name'] . '[/zrl]';
$alink = '[zrl=' . $observer['xchan_url'] . ']' . $observer['xchan_name'] . '[/zrl]';

View File

@ -109,10 +109,8 @@ function tagger_content(&$a) {
$arr['owner_xchan'] = $item['owner_xchan'];
$arr['author_xchan'] = $channel['channel_hash'];
$arr['item_flags'] = ITEM_ORIGIN;
if($item['item_flags'] & ITEM_WALL)
$arr['item_flags'] |= ITEM_WALL;
$arr['item_origin'] = 1;
$arr['item_wall'] = ((intval($item['item_wall'])) ? 1 : 0);
$ulink = '[zrl=' . $channel['xchan_url'] . ']' . $channel['channel_name'] . '[/zrl]';
$alink = '[zrl=' . $item['xchan_url'] . ']' . $item['xchan_name'] . '[/zrl]';

View File

@ -182,8 +182,10 @@ function thing_init(&$a) {
$arr['owner_xchan'] = $channel['channel_hash'];
$arr['author_xchan'] = $channel['channel_hash'];
$arr['item_origin'] = 1;
$arr['item_wall'] = 1;
$arr['item_thread_top'] = 1;
$arr['item_flags'] = ITEM_ORIGIN|ITEM_WALL|ITEM_THREAD_TOP;
$ulink = '[zrl=' . $channel['xchan_url'] . ']' . $channel['channel_name'] . '[/zrl]';
$plink = '[zrl=' . $term['url'] . ']' . $term['term'] . '[/zrl]';