Use "last-item" in the contact table instead of an expensive sql query
This commit is contained in:
parent
78cead6c11
commit
e5c7ce0902
8 changed files with 148 additions and 56 deletions
|
|
@ -798,43 +798,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
|
|||
$current_post = $r[0]['id'];
|
||||
logger('item_store: created item ' . $current_post);
|
||||
|
||||
// Set "success_update" and "last-item" to the date of the last time we heard from this contact
|
||||
// This can be used to filter for inactive contacts.
|
||||
// Only do this for public postings to avoid privacy problems, since poco data is public.
|
||||
// Don't set this value if it isn't from the owner (could be an author that we don't know)
|
||||
|
||||
$update = (!$arr['private'] AND (($arr["author-link"] === $arr["owner-link"]) OR ($arr["parent-uri"] === $arr["uri"])));
|
||||
|
||||
// Is it a forum? Then we don't care about the rules from above
|
||||
if (!$update AND ($arr["network"] == NETWORK_DFRN) AND ($arr["parent-uri"] === $arr["uri"])) {
|
||||
$isforum = q("SELECT `forum` FROM `contact` WHERE `id` = %d AND `forum`",
|
||||
intval($arr['contact-id']));
|
||||
if ($isforum)
|
||||
$update = true;
|
||||
}
|
||||
|
||||
if ($update)
|
||||
q("UPDATE `contact` SET `success_update` = '%s', `last-item` = '%s' WHERE `id` = %d",
|
||||
dbesc($arr['received']),
|
||||
dbesc($arr['received']),
|
||||
intval($arr['contact-id'])
|
||||
);
|
||||
|
||||
// Now do the same for the system wide contacts with uid=0
|
||||
if (!$arr['private']) {
|
||||
q("UPDATE `contact` SET `success_update` = '%s', `last-item` = '%s' WHERE `id` = %d",
|
||||
dbesc($arr['received']),
|
||||
dbesc($arr['received']),
|
||||
intval($arr['owner-id'])
|
||||
);
|
||||
|
||||
if ($arr['owner-id'] != $arr['author-id'])
|
||||
q("UPDATE `contact` SET `success_update` = '%s', `last-item` = '%s' WHERE `id` = %d",
|
||||
dbesc($arr['received']),
|
||||
dbesc($arr['received']),
|
||||
intval($arr['author-id'])
|
||||
);
|
||||
}
|
||||
item_set_last_item($arr);
|
||||
} else {
|
||||
logger('item_store: could not locate created item');
|
||||
return 0;
|
||||
|
|
@ -931,6 +895,51 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
|
|||
return $current_post;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set "success_update" and "last-item" to the date of the last time we heard from this contact
|
||||
*
|
||||
* This can be used to filter for inactive contacts.
|
||||
* Only do this for public postings to avoid privacy problems, since poco data is public.
|
||||
* Don't set this value if it isn't from the owner (could be an author that we don't know)
|
||||
*
|
||||
* @param array $arr Contains the just posted item record
|
||||
*/
|
||||
function item_set_last_item($arr) {
|
||||
|
||||
$update = (!$arr['private'] AND (($arr["author-link"] === $arr["owner-link"]) OR ($arr["parent-uri"] === $arr["uri"])));
|
||||
|
||||
// Is it a forum? Then we don't care about the rules from above
|
||||
if (!$update AND ($arr["network"] == NETWORK_DFRN) AND ($arr["parent-uri"] === $arr["uri"])) {
|
||||
$isforum = q("SELECT `forum` FROM `contact` WHERE `id` = %d AND `forum`",
|
||||
intval($arr['contact-id']));
|
||||
if ($isforum)
|
||||
$update = true;
|
||||
}
|
||||
|
||||
if ($update)
|
||||
q("UPDATE `contact` SET `success_update` = '%s', `last-item` = '%s' WHERE `id` = %d",
|
||||
dbesc($arr['received']),
|
||||
dbesc($arr['received']),
|
||||
intval($arr['contact-id'])
|
||||
);
|
||||
|
||||
// Now do the same for the system wide contacts with uid=0
|
||||
if (!$arr['private']) {
|
||||
q("UPDATE `contact` SET `success_update` = '%s', `last-item` = '%s' WHERE `id` = %d",
|
||||
dbesc($arr['received']),
|
||||
dbesc($arr['received']),
|
||||
intval($arr['owner-id'])
|
||||
);
|
||||
|
||||
if ($arr['owner-id'] != $arr['author-id'])
|
||||
q("UPDATE `contact` SET `success_update` = '%s', `last-item` = '%s' WHERE `id` = %d",
|
||||
dbesc($arr['received']),
|
||||
dbesc($arr['received']),
|
||||
intval($arr['author-id'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function item_body_set_hashtags(&$item) {
|
||||
|
||||
$tags = get_tags($item["body"]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue