Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/maps.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2022-02-14 20:53:13 +0300
committerThomas Citharel <tcit@tcit.fr>2022-02-14 20:53:13 +0300
commitcb32a781d21777a181d3876157c05bfdc59f871b (patch)
tree483ca85b9d4ca21a938942e16026b933b15c6bd1 /lib
parent10d8124214e839eb28c5e40eb2a653196cb1f392 (diff)
Replace use of IConfig with IMemcache to store the last address lookup
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'lib')
-rw-r--r--lib/Service/AddressService.php16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/Service/AddressService.php b/lib/Service/AddressService.php
index 933dbf1f..1536d1f0 100644
--- a/lib/Service/AddressService.php
+++ b/lib/Service/AddressService.php
@@ -13,15 +13,14 @@
namespace OCA\Maps\Service;
use \OCA\Maps\BackgroundJob\LookupMissingGeoJob;
+use OCP\ICacheFactory;
use \OCP\ILogger;
-use \OCP\IConfig;
use \OCP\IDBConnection;
use \OCP\BackgroundJob\IJobList;
use \OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\IMemcache;
use \Sabre\VObject\Reader;
use \OCP\Files\IAppData;
-use \OCP\Files\SimpleFS\ISimpleFile;
-use \OCP\Files\NotFoundException;
/**
* Class AddressService
@@ -45,11 +44,14 @@ class AddressService {
private $jobList;
private $appData;
- public function __construct(IConfig $config, ILogger $logger, IJobList $jobList,
+ /** @var IMemcache */
+ private $memcache;
+
+ public function __construct(ICacheFactory $cacheFactory, ILogger $logger, IJobList $jobList,
IAppData $appData, IDBConnection $dbconnection) {
$this->dbconnection = $dbconnection;
$this->qb = $dbconnection->getQueryBuilder();
- $this->config = $config;
+ $this->memcache = $cacheFactory->createLocal('maps');
$this->logger = $logger;
$this->jobList = $jobList;
$this->appData = $appData;
@@ -155,7 +157,7 @@ class AddressService {
// looks up the address on external provider returns lat, lon, lookupstate
// do lookup only if last one occured more than one second ago
private function lookupAddressExternal($adr) {
- if (time() - intval($this->config->getAppValue('maps', 'lastAddressLookup')) >= 1) {
+ if (time() - intval($this->memcache->get('lastAddressLookup')) >= 1) {
$opts = [
'http' => [
'method' => 'GET',
@@ -180,7 +182,7 @@ class AddressService {
$result = \json_decode($result_json, true);
if (!(key_exists('request_failed', $result) AND $result['request_failed'])) {
$this->logger->debug('External looked up address: ' . $adr . ' with result' . print_r($result, true));
- $this->config->setAppValue('maps', 'lastAddressLookup', time());
+ $this->memcache->set('lastAddressLookup', time());
if (sizeof($result) > 0) {
if (key_exists('lat', $result[0]) AND
key_exists('lon', $result[0])