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

github.com/nextcloud/lookup-server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Schießle <bjoern@schiessle.org>2017-06-20 11:39:50 +0300
committerGitHub <noreply@github.com>2017-06-20 11:39:50 +0300
commit98e8f448626a62aba037c6fec61083c539218b2f (patch)
treedd8331b9c2388d11690ac61e3402a0389874c9f5
parent8d7d4f440ed6fbc51ba11789d01f4ad8230b48ae (diff)
parentd5e0f66eb518732570403595099d954027391c6d (diff)
Merge pull request #14 from nextcloud/ignore-karma-in-global-scale-mode
ignore karma in a global scale setup
-rwxr-xr-xserver/config/config.sample.php3
-rw-r--r--server/lib/UserManager.php63
-rw-r--r--server/src/config.php1
-rw-r--r--server/src/dependencies.php2
4 files changed, 65 insertions, 4 deletions
diff --git a/server/config/config.sample.php b/server/config/config.sample.php
index aa761cf..5154854 100755
--- a/server/config/config.sample.php
+++ b/server/config/config.sample.php
@@ -53,6 +53,9 @@ $CONFIG = [
// Public Server Url
'PUBLIC_URL' => 'http://dev/nextcloud/lookup-server',
+ // does the lookup server run in a global scale setup
+ 'GLOBAL_SCALE' => false,
+
// twitter oauth credentials, needed to perform twitter verification
'TWITTER' => [
'CONSUMER_KEY' => '',
diff --git a/server/lib/UserManager.php b/server/lib/UserManager.php
index d1d0486..1ad85ba 100644
--- a/server/lib/UserManager.php
+++ b/server/lib/UserManager.php
@@ -28,6 +28,9 @@ class UserManager {
/** @var int try max. 10 times to verify a account */
private $maxVerifyTries = 10;
+ /** @var bool */
+ private $globalScaleMode;
+
/**
* UserManager constructor.
*
@@ -36,17 +39,20 @@ class UserManager {
* @param Website $websiteValidator
* @param Twitter $twitterValidator
* @param SignatureHandler $signatureHandler
+ * @param bool globalScaleMode
*/
public function __construct(\PDO $db,
Email $emailValidator,
Website $websiteValidator,
Twitter $twitterValidator,
- SignatureHandler $signatureHandler) {
+ SignatureHandler $signatureHandler,
+ $globalScaleMode) {
$this->db = $db;
$this->emailValidator = $emailValidator;
$this->websiteValidator = $websiteValidator;
$this->twitterValidator = $twitterValidator;
$this->signatureHandler = $signatureHandler;
+ $this->globalScaleMode = $globalScaleMode;
}
public function search(Request $request, Response $response) {
@@ -66,6 +72,24 @@ class UserManager {
return $response;
}
+ if ($this->globalScaleMode === true) {
+ // in a global scale setup we ignore the karma
+ $users = $this->searchNoKarma();
+ } else {
+ $users = $this->searchKarma();
+ }
+
+ $response->getBody()->write(json_encode($users));
+ return $response;
+ }
+
+ /**
+ * return all results with karma >= 1
+ *
+ * @param $search
+ * @return array
+ */
+ private function searchKarma($search) {
$stmt = $this->db->prepare('SELECT *
FROM (
SELECT userId AS userId, SUM(valid) AS karma
@@ -94,8 +118,41 @@ LIMIT 50');
}
$stmt->closeCursor();
- $response->getBody()->write(json_encode($users));
- return $response;
+ return $users;
+ }
+
+
+ /**
+ * return all results, ignoring the karma
+ *
+ * @param $search
+ * @return array
+ */
+ private function searchNoKarma($search) {
+ $stmt = $this->db->prepare('SELECT *
+FROM `store`
+ WHERE userId IN (
+ SELECT DISTINCT userId
+ FROM `store`
+ WHERE v LIKE :search
+ )
+ GROUP BY userId
+ LIMIT 50');
+ $search = '%' . $search . '%';
+ $stmt->bindParam(':search', $search, \PDO::PARAM_STR);
+ $stmt->execute();
+
+ /*
+ * TODO: Better fuzzy search?
+ */
+
+ $users = [];
+ while($data = $stmt->fetch()) {
+ $users[] = $this->getForUserId((int)$data['userId']);
+ }
+ $stmt->closeCursor();
+
+ return $users;
}
private function getExactCloudId($cloudId) {
diff --git a/server/src/config.php b/server/src/config.php
index a702141..0ee302a 100644
--- a/server/src/config.php
+++ b/server/src/config.php
@@ -16,6 +16,7 @@ return [
'emailfrom' => $CONFIG['EMAIL_SENDER'],
'replication_auth' => $CONFIG['REPLICATION_AUTH'],
'replication_hosts' => $CONFIG['REPLICATION_HOSTS'],
+ 'global_scale' => $CONFIG['GLOBAL_SCALE'],
'twitter' => [
'consumer_key' => $CONFIG['TWITTER']['CONSUMER_KEY'],
'consumer_secret' => $CONFIG['TWITTER']['CONSUMER_SECRET'],
diff --git a/server/src/dependencies.php b/server/src/dependencies.php
index 32cedf3..c2a9d80 100644
--- a/server/src/dependencies.php
+++ b/server/src/dependencies.php
@@ -9,7 +9,7 @@ $container['db'] = function($c) {
return $pdo;
};
$container['UserManager'] = function($c) {
- return new \LookupServer\UserManager($c->db, $c->EmailValidator, $c->WebsiteValidator, $c->TwitterValidator, $c->SignatureHandler);
+ return new \LookupServer\UserManager($c->db, $c->EmailValidator, $c->WebsiteValidator, $c->TwitterValidator, $c->SignatureHandler, $c['settings']['global_scale']);
};
$container['SignatureHandler'] = function($c) {
return new \LookupServer\SignatureHandler();