Merge pull request #2878 from Hypolite/improvement/ping-performance
Improving ping.php performance
This commit is contained in:
@@ -325,15 +325,15 @@ function datetimesel($format, $min, $max, $default, $label, $id = 'datetimepicke
|
||||
* Results relative to current timezone.
|
||||
* Limited to range of timestamps.
|
||||
*
|
||||
* @param string $posted_date
|
||||
* @param string $posted_date MySQL-formatted date string (YYYY-MM-DD HH:MM:SS)
|
||||
* @param string $format (optional) Parsed with sprintf()
|
||||
* <tt>%1$d %2$s ago</tt>, e.g. 22 hours ago, 1 minute ago
|
||||
*
|
||||
*
|
||||
* @return string with relative date
|
||||
*/
|
||||
function relative_date($posted_date,$format = null) {
|
||||
function relative_date($posted_date, $format = null) {
|
||||
|
||||
$localtime = datetime_convert('UTC',date_default_timezone_get(),$posted_date);
|
||||
$localtime = $posted_date . ' UTC';
|
||||
|
||||
$abs = strtotime($localtime);
|
||||
|
||||
@@ -347,13 +347,6 @@ function relative_date($posted_date,$format = null) {
|
||||
return t('less than a second ago');
|
||||
}
|
||||
|
||||
/*
|
||||
$time_append = '';
|
||||
if ($etime >= 86400) {
|
||||
$time_append = ' ('.$localtime.')';
|
||||
}
|
||||
*/
|
||||
|
||||
$a = array( 12 * 30 * 24 * 60 * 60 => array( t('year'), t('years')),
|
||||
30 * 24 * 60 * 60 => array( t('month'), t('months')),
|
||||
7 * 24 * 60 * 60 => array( t('week'), t('weeks')),
|
||||
@@ -368,10 +361,11 @@ function relative_date($posted_date,$format = null) {
|
||||
if ($d >= 1) {
|
||||
$r = round($d);
|
||||
// translators - e.g. 22 hours ago, 1 minute ago
|
||||
if(! $format)
|
||||
if (!$format) {
|
||||
$format = t('%1$d %2$s ago');
|
||||
}
|
||||
|
||||
return sprintf( $format,$r, (($r == 1) ? $str[0] : $str[1]));
|
||||
return sprintf($format, $r, (($r == 1) ? $str[0] : $str[1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1039,6 +1039,8 @@ function db_definition($charset) {
|
||||
"seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
|
||||
"verb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"otype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
|
||||
"name_cache" => array("type" => "tinytext"),
|
||||
"msg_cache" => array("type" => "mediumtext")
|
||||
),
|
||||
"indexes" => array(
|
||||
"PRIMARY" => array("id"),
|
||||
|
||||
@@ -418,6 +418,7 @@ function notification($params) {
|
||||
$datarray = array();
|
||||
$datarray['hash'] = $hash;
|
||||
$datarray['name'] = $params['source_name'];
|
||||
$datarray['name_cache'] = strip_tags(bbcode($params['source_name']));
|
||||
$datarray['url'] = $params['source_link'];
|
||||
$datarray['photo'] = $params['source_photo'];
|
||||
$datarray['date'] = datetime_convert();
|
||||
@@ -439,7 +440,7 @@ function notification($params) {
|
||||
|
||||
// create notification entry in DB
|
||||
|
||||
$r = q("INSERT INTO `notify` (`hash`, `name`, `url`, `photo`, `date`, `uid`, `link`, `iid`, `parent`, `type`, `verb`, `otype`)
|
||||
$r = q("INSERT INTO `notify` (`hash`, `name`, `url`, `photo`, `date`, `uid`, `link`, `iid`, `parent`, `type`, `verb`, `otype`, `name_cache`)
|
||||
values('%s', '%s', '%s', '%s', '%s', %d, '%s', %d, %d, %d, '%s', '%s')",
|
||||
dbesc($datarray['hash']),
|
||||
dbesc($datarray['name']),
|
||||
@@ -452,7 +453,8 @@ function notification($params) {
|
||||
intval($datarray['parent']),
|
||||
intval($datarray['type']),
|
||||
dbesc($datarray['verb']),
|
||||
dbesc($datarray['otype'])
|
||||
dbesc($datarray['otype']),
|
||||
dbesc($datarray["name_cache"])
|
||||
);
|
||||
|
||||
$r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' AND `uid` = %d LIMIT 1",
|
||||
@@ -494,8 +496,10 @@ function notification($params) {
|
||||
|
||||
$itemlink = $a->get_baseurl().'/notify/view/'.$notify_id;
|
||||
$msg = replace_macros($epreamble, array('$itemlink' => $itemlink));
|
||||
$r = q("UPDATE `notify` SET `msg` = '%s' WHERE `id` = %d AND `uid` = %d",
|
||||
$msg_cache = format_notification_message($datarray['name_cache'], strip_tags(bbcode($msg)));
|
||||
$r = q("UPDATE `notify` SET `msg` = '%s', `msg_cache` = '%s' WHERE `id` = %d AND `uid` = %d",
|
||||
dbesc($msg),
|
||||
dbesc($msg_cache),
|
||||
intval($notify_id),
|
||||
intval($params['uid'])
|
||||
);
|
||||
@@ -778,4 +782,27 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
|
||||
if (isset($params["type"]))
|
||||
notification($params);
|
||||
}
|
||||
?>
|
||||
|
||||
/**
|
||||
* @brief Formats a notification message with the notification author
|
||||
*
|
||||
* Replace the name with {0} but ensure to make that only once. The {0} is used
|
||||
* later and prints the name in bold.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $message
|
||||
* @return string Formatted message
|
||||
*/
|
||||
function format_notification_message($name, $message) {
|
||||
if ($name != '') {
|
||||
$pos = strpos($message, $name);
|
||||
} else {
|
||||
$pos = false;
|
||||
}
|
||||
|
||||
if ($pos !== false) {
|
||||
$message = substr_replace($message, '{0}', $pos, strlen($name));
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
@@ -40,6 +40,19 @@ function ref_session_read($id) {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Standard PHP session write callback
|
||||
*
|
||||
* This callback updates the DB-stored session data and/or the expiration depending
|
||||
* on the case. Uses the $session_expire global for existing session, 5 minutes
|
||||
* for newly created session.
|
||||
*
|
||||
* @global bool $session_exists Whether a session with the given id already exists
|
||||
* @global int $session_expire Session expiration delay in seconds
|
||||
* @param string $id Session ID with format: [a-z0-9]{26}
|
||||
* @param string $data Serialized session data
|
||||
* @return boolean Returns false if parameters are missing, true otherwise
|
||||
*/
|
||||
function ref_session_write($id, $data) {
|
||||
global $session_exists, $session_expire;
|
||||
|
||||
@@ -66,10 +79,11 @@ function ref_session_write($id, $data) {
|
||||
SET `expire` = '%s'
|
||||
WHERE `expire` != '%s' AND `sid` = '%s'",
|
||||
dbesc($expire), dbesc($expire), dbesc($id));
|
||||
} else
|
||||
} else {
|
||||
$r = q("INSERT INTO `session`
|
||||
SET `sid` = '%s', `expire` = '%s', `data` = '%s'",
|
||||
dbesc($id), dbesc($default_expire), dbesc($data));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user