Browse Source

Move Global Functions - Part 3

- Replaced every CACHE definition
- Moved check_url to App->checkURL()
- Removed unused definition "ZCURL_TIMEOUT"
pull/5977/head
Philipp Holzer 3 years ago
parent
commit
4392858662
No known key found for this signature in database GPG Key ID: 517BE60E2CE5C8A5
  1. 46
      boot.php
  2. 2
      index.php
  3. 2
      mod/ping.php
  4. 4
      mod/search.php
  5. 19
      src/App.php
  6. 4
      src/Content/OEmbed.php
  7. 4
      src/Model/GContact.php
  8. 4
      src/Model/Photo.php
  9. 4
      src/Model/Profile.php
  10. 2
      src/Network/Probe.php
  11. 2
      src/Protocol/ActivityPub/Transmitter.php
  12. 6
      src/Protocol/Diaspora.php
  13. 2
      src/Protocol/OStatus.php
  14. 2
      src/Util/JsonLD.php
  15. 2
      src/Worker/DiscoverPoCo.php
  16. 8
      src/Worker/Queue.php

46
boot.php

@ -121,24 +121,6 @@ define('LOGGER_DATA', 4);
define('LOGGER_ALL', 5);
/* @}*/
/**
* @name Cache
* @deprecated since version 3.6
* @see Cache
*
* Cache levels
* @{
*/
define('CACHE_MONTH', Cache::MONTH);
define('CACHE_WEEK', Cache::WEEK);
define('CACHE_DAY', Cache::DAY);
define('CACHE_HOUR', Cache::HOUR);
define('CACHE_HALF_HOUR', Cache::HALF_HOUR);
define('CACHE_QUARTER_HOUR', Cache::QUARTER_HOUR);
define('CACHE_FIVE_MINUTES', Cache::FIVE_MINUTES);
define('CACHE_MINUTE', Cache::MINUTE);
/* @}*/
/**
* @name Register
*
@ -212,11 +194,6 @@ $netgroup_ids = [
*/
define('MAX_LIKERS', 75);
/**
* Communication timeout
*/
define('ZCURL_TIMEOUT', (-1));
/**
* @name Notify
*
@ -502,29 +479,6 @@ function check_db($via_worker)
}
}
/**
* Sets the base url for use in cmdline programs which don't have
* $_SERVER variables
*
* @param object $a App
*/
function check_url(App $a)
{
$url = Config::get('system', 'url');
// if the url isn't set or the stored url is radically different
// than the currently visited url, store the current value accordingly.
// "Radically different" ignores common variations such as http vs https
// and www.example.com vs example.com.
// We will only change the url to an ip address if there is no existing setting
if (empty($url) || (!link_compare($url, System::baseUrl())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $a->getHostName()))) {
Config::set('system', 'url', System::baseUrl());
}
return;
}
/**
* @brief Automatic database updates
* @param object $a App

2
index.php

@ -172,7 +172,7 @@ if ($a->getMode()->isInstall() && $a->module != 'view') {
} elseif (!$a->getMode()->has(App\Mode::MAINTENANCEDISABLED) && $a->module != 'view') {
$a->module = 'maintenance';
} else {
check_url($a);
$a->checkURL();
check_db(false);
Addon::check();
}

2
mod/ping.php

@ -221,7 +221,7 @@ function ping_init(App $a)
DBA::escape(DateTimeFormat::utcNow())
);
if (DBA::isResult($ev)) {
Cache::set($cachekey, $ev, CACHE_HOUR);
Cache::set($cachekey, $ev, Cache::HOUR);
}
}

4
mod/search.php

@ -136,9 +136,9 @@ function search_content(App $a) {
"description" => L10n::t("Only one search per minute is permitted for not logged in users.")]);
killme();
}
Cache::set("remote_search:".$remote, json_encode(["time" => time(), "accesses" => $resultdata->accesses + 1]), CACHE_HOUR);
Cache::set("remote_search:".$remote, json_encode(["time" => time(), "accesses" => $resultdata->accesses + 1]), Cache::HOUR);
} else
Cache::set("remote_search:".$remote, json_encode(["time" => time(), "accesses" => 1]), CACHE_HOUR);
Cache::set("remote_search:".$remote, json_encode(["time" => time(), "accesses" => 1]), Cache::HOUR);
}
Nav::setSelected('search');

19
src/App.php

@ -1607,4 +1607,23 @@ class App
return $default;
}
/**
* Sets the base url for use in cmdline programs which don't have
* $_SERVER variables
*/
public function checkURL()
{
$url = Config::get('system', 'url');
// if the url isn't set or the stored url is radically different
// than the currently visited url, store the current value accordingly.
// "Radically different" ignores common variations such as http vs https
// and www.example.com vs example.com.
// We will only change the url to an ip address if there is no existing setting
if (empty($url) || (!link_compare($url, $this->getBaseURL())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $this->getHostName()))) {
Config::set('system', 'url', $this->getBaseURL());
}
}
}

4
src/Content/OEmbed.php

@ -120,9 +120,9 @@ class OEmbed
'content' => $json_string,
'created' => DateTimeFormat::utcNow()
], true);
$cache_ttl = CACHE_DAY;
$cache_ttl = Cache::DAY;
} else {
$cache_ttl = CACHE_FIVE_MINUTES;
$cache_ttl = Cache::FIVE_MINUTES;
}
Cache::set($cache_key, $json_string, $cache_ttl);

4
src/Model/GContact.php

@ -468,7 +468,7 @@ class GContact
* Uncommented because the result of the queries are to big to store it in the cache.
* We need to decide if we want to change the db column type or if we want to delete it.
*/
//Cache::set("suggestion_query:".$uid.":".$start.":".$limit, $r, CACHE_FIVE_MINUTES);
//Cache::set("suggestion_query:".$uid.":".$start.":".$limit, $r, Cache::FIVE_MINUTES);
return $r;
}
@ -509,7 +509,7 @@ class GContact
* Uncommented because the result of the queries are to big to store it in the cache.
* We need to decide if we want to change the db column type or if we want to delete it.
*/
//Cache::set("suggestion_query:".$uid.":".$start.":".$limit, $list, CACHE_FIVE_MINUTES);
//Cache::set("suggestion_query:".$uid.":".$start.":".$limit, $list, Cache::FIVE_MINUTES);
return $list;
}

4
src/Model/Photo.php

@ -253,7 +253,7 @@ class Photo
DBA::escape(L10n::t('Contact Photos'))
);
}
Cache::set($key, $albums, CACHE_DAY);
Cache::set($key, $albums, Cache::DAY);
}
return $albums;
}
@ -265,7 +265,7 @@ class Photo
public static function clearAlbumCache($uid)
{
$key = "photo_albums:".$uid.":".local_user().":".remote_user();
Cache::set($key, null, CACHE_DAY);
Cache::set($key, null, Cache::DAY);
}
/**

4
src/Model/Profile.php

@ -577,7 +577,7 @@ class Profile
);
if (DBA::isResult($s)) {
$r = DBA::toArray($s);
Cache::set($cachekey, $r, CACHE_HOUR);
Cache::set($cachekey, $r, Cache::HOUR);
}
}
@ -1037,7 +1037,7 @@ class Profile
logger('URL ' . $my_url . ' already tried to authenticate.', LOGGER_DEBUG);
return;
} else {
Cache::set($cachekey, true, CACHE_MINUTE);
Cache::set($cachekey, true, Cache::MINUTE);
}
logger('Not authenticated. Invoking reverse magic-auth for ' . $my_url, LOGGER_DEBUG);

2
src/Network/Probe.php

@ -381,7 +381,7 @@ class Probe
// Only store into the cache if the value seems to be valid
if (!in_array($data['network'], [Protocol::PHANTOM, Protocol::MAIL])) {
Cache::set("Probe::uri:".$network.":".$uri, $data, CACHE_DAY);
Cache::set("Probe::uri:".$network.":".$uri, $data, Cache::DAY);
/// @todo temporary fix - we need a real contact update function that updates only changing fields
/// The biggest problem is the avatar picture that could have a reduced image size.

2
src/Protocol/ActivityPub/Transmitter.php

@ -545,7 +545,7 @@ class Transmitter
$data = ActivityPub\Transmitter::createActivityFromItem($item_id);
Cache::set($cachekey, $data, CACHE_QUARTER_HOUR);
Cache::set($cachekey, $data, Cache::QUARTER_HOUR);
return $data;
}

6
src/Protocol/Diaspora.php

@ -3205,7 +3205,7 @@ class Diaspora
logger("Send participation for ".$item["guid"]." by ".$author, LOGGER_DEBUG);
// It doesn't matter what we store, we only want to avoid sending repeated notifications for the same item
Cache::set($cachekey, $item["guid"], CACHE_QUARTER_HOUR);
Cache::set($cachekey, $item["guid"], Cache::QUARTER_HOUR);
return self::buildAndTransmit($owner, $contact, "participation", $message);
}
@ -3575,7 +3575,7 @@ class Diaspora
$msg = ["type" => $type, "message" => $message];
Cache::set($cachekey, $msg, CACHE_QUARTER_HOUR);
Cache::set($cachekey, $msg, Cache::QUARTER_HOUR);
return $msg;
}
@ -3702,7 +3702,7 @@ class Diaspora
$comment['thread_parent_guid'] = self::getGuidFromUri($item['thr-parent'], $item['uid']);
}
Cache::set($cachekey, $comment, CACHE_QUARTER_HOUR);
Cache::set($cachekey, $comment, Cache::QUARTER_HOUR);
return($comment);
}

2
src/Protocol/OStatus.php

@ -2210,7 +2210,7 @@ class OStatus
$feeddata = trim($doc->saveXML());
$msg = ['feed' => $feeddata, 'last_update' => $last_update];
Cache::set($cachekey, $msg, CACHE_QUARTER_HOUR);
Cache::set($cachekey, $msg, Cache::QUARTER_HOUR);
logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created, LOGGER_DEBUG);

2
src/Util/JsonLD.php

@ -43,7 +43,7 @@ class JsonLD
}
$data = jsonld_default_document_loader($url);
Cache::set('documentLoader:' . $url, $data, CACHE_DAY);
Cache::set('documentLoader:' . $url, $data, Cache::DAY);
return $data;
}

2
src/Worker/DiscoverPoCo.php

@ -258,7 +258,7 @@ class DiscoverPoCo
}
}
}
Cache::set("dirsearch:".$search, time(), CACHE_DAY);
Cache::set("dirsearch:".$search, time(), Cache::DAY);
}
/**

8
src/Worker/Queue.php

@ -87,7 +87,7 @@ class Queue
logger("Check server " . $server . " (" . $contact["network"] . ")");
$vital = PortableContact::checkServer($server, $contact["network"], true);
Cache::set($cachekey_server . $server, $vital, CACHE_MINUTE);
Cache::set($cachekey_server . $server, $vital, Cache::MINUTE);
}
if (!is_null($vital) && !$vital) {
@ -119,7 +119,7 @@ class Queue
QueueModel::removeItem($q_item['id']);
} else {
QueueModel::updateTime($q_item['id']);
Cache::set($cachekey_deadguy . $contact['notify'], true, CACHE_MINUTE);
Cache::set($cachekey_deadguy . $contact['notify'], true, Cache::MINUTE);
}
break;
@ -129,7 +129,7 @@ class Queue
if ($deliver_status == -1) {
QueueModel::updateTime($q_item['id']);
Cache::set($cachekey_deadguy . $contact['notify'], true, CACHE_MINUTE);
Cache::set($cachekey_deadguy . $contact['notify'], true, Cache::MINUTE);
} else {
QueueModel::removeItem($q_item['id']);
}
@ -144,7 +144,7 @@ class Queue
QueueModel::removeItem($q_item['id']);
} else {
QueueModel::updateTime($q_item['id']);
Cache::set($cachekey_deadguy . $contact['notify'], true, CACHE_MINUTE);
Cache::set($cachekey_deadguy . $contact['notify'], true, Cache::MINUTE);
}
break;

Loading…
Cancel
Save