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

github.com/nextcloud/fulltextsearch.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaita <maxence@pontapreta.net>2016-12-03 05:23:41 +0300
committerdaita <maxence@pontapreta.net>2016-12-03 05:23:41 +0300
commit0ad3a54150b43a00de6d7b8208f38943def20204 (patch)
treecb77b92f2003c5f2b9ab9654e417e2a77a705af5
parent8766b23334ff58bfc25a5f1a8a9847babb398f79 (diff)
#75 - implement database queue
-rw-r--r--appinfo/database-disabled.xml40
-rw-r--r--appinfo/database.xml29
-rw-r--r--lib/AppInfo/Application.php16
-rw-r--r--lib/Db/IndexMapper.php60
-rw-r--r--lib/Db/LiveQueue.php (renamed from lib/Db/Index.php)42
-rw-r--r--lib/Db/LiveQueueMapper.php74
-rw-r--r--lib/Items/ItemQueue.php2
-rw-r--r--lib/Service/ConfigService.php6
-rw-r--r--lib/Service/QueueService.php76
9 files changed, 192 insertions, 153 deletions
diff --git a/appinfo/database-disabled.xml b/appinfo/database-disabled.xml
deleted file mode 100644
index 36f8c07..0000000
--- a/appinfo/database-disabled.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1" ?>
-<database>
- <name>*dbname*</name>
- <create>true</create>
- <overwrite>false</overwrite>
- <charset>utf8</charset>
-
- <table>
- <name>*dbprefix*nextant_index</name>
- <declaration>
- <field>
- <name>fileid</name>
- <type>integer</type>
- <default>0</default>
- <notnull>true</notnull>
- <length>4</length>
- </field>
- <field>
- <name>clef</name>
- <type>text</type>
- <notnull>true</notnull>
- <length>64</length>
- </field>
- <field>
- <name>creation</name>
- <type>timestamp</type>
- <default></default>
- <notnull>false</notnull>
- </field>
- <index>
- <name>nextant_clef</name>
- <unique>true</unique>
- <field>
- <name>fileid</name>
- <name>clef</name>
- </field>
- </index>
- </declaration>
- </table>
-</database> \ No newline at end of file
diff --git a/appinfo/database.xml b/appinfo/database.xml
new file mode 100644
index 0000000..0adbc94
--- /dev/null
+++ b/appinfo/database.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<database>
+ <name>*dbname*</name>
+ <create>true</create>
+ <overwrite>false</overwrite>
+ <charset>utf8</charset>
+
+ <table>
+ <name>*dbprefix*nextant_live_queue</name>
+ <declaration>
+ <field>
+ <name>id</name>
+ <type>integer</type>
+ <notnull>true</notnull>
+ <autoincrement>true</autoincrement>
+ <unsigned>true</unsigned>
+ <primary>true</primary>
+ <length>8</length>
+ </field>
+ <field>
+ <name>item</name>
+ <type>text</type>
+ <notnull>true</notnull>
+ <length>512</length>
+ </field>
+ </declaration>
+ </table>
+
+</database> \ No newline at end of file
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index d8d08a5..8b73f8e 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -28,7 +28,7 @@ namespace OCA\Nextant\AppInfo;
use \OCA\Nextant\Controller\SettingsController;
use \OCA\Nextant\Controller\SearchController;
-use \OCA\Nextant\Db\IndexMapper;
+use \OCA\Nextant\Db\LiveQueueMapper;
use \OCA\Nextant\Events\FilesEvents;
use \OCA\Nextant\Events\BookmarksEvents;
use \OCA\Nextant\Hooks\FilesHooks;
@@ -78,7 +78,7 @@ class Application extends App
});
$container->registerService('QueueService', function ($c) {
- return new QueueService($c->query('ConfigService'), $c->query('IndexService'), $c->query('FileService'), $c->query('MiscService'));
+ return new QueueService($c->query('LiveQueueMapper'), $c->query('ConfigService'), $c->query('IndexService'), $c->query('FileService'), $c->query('MiscService'));
});
$container->registerService('FileService', function ($c) {
@@ -101,8 +101,8 @@ class Application extends App
return new SolrToolsService($c->query('SolrService'), $c->query('ConfigService'), $c->query('MiscService'));
});
- $container->registerService('IndexMapper', function ($c) {
- return new IndexMapper($c->query('ServerContainer')
+ $container->registerService('LiveQueueMapper', function ($c) {
+ return new LiveQueueMapper($c->query('ServerContainer')
->getDb());
});
@@ -114,8 +114,6 @@ class Application extends App
return new BookmarksEvents($c->query('ConfigService'), $c->query('UserId'), $c->query('SolrService'), $c->query('MiscService'));
});
- // $container->query('IndexMapper')->insert(new IndexEntity(array(userid => 2, 'path' => '/toto', 'clef' => 'CLEFCLEF')));
-
$container->registerService('SearchController', function ($c) {
return new SearchController($c->query('AppName'), $c->query('Request'), $c->query('UserId'), $c->query('GroupManager'), $c->query('ConfigService'), $c->query('SolrService'), $c->query('FileService'), $c->query('BookmarkService'), $c->query('MiscService'));
});
@@ -167,6 +165,12 @@ class Application extends App
->getRootFolder();
});
+ // Translates
+ $container->registerService('L10N', function (IContainer $c) {
+ return $c->query('ServerContainer')
+ ->getL10N($c->query('AppName'));
+ });
+
$container->registerService('SolariumClient', function ($c) {
$toS = $c->query('ConfigService')
->toSolarium();
diff --git a/lib/Db/IndexMapper.php b/lib/Db/IndexMapper.php
deleted file mode 100644
index 304e854..0000000
--- a/lib/Db/IndexMapper.php
+++ /dev/null
@@ -1,60 +0,0 @@
-<?php
-
-/**
- * Nextcloud - nextant
- *
- * This file is licensed under the Affero General Public License version 3 or
- * later. See the COPYING file.
- *
- * @author Maxence Lange <maxence@pontapreta.net>
- * @copyright Maxence Lange 2016
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-// namespace OCA\Nextant\Db;
-
-// use OCP\IDBConnection;
-// use OCP\AppFramework\Db\Mapper;
-
-// class IndexMapper extends Mapper
-// {
-
-// const TABLENAME = 'nextant_index';
-
-// public function __construct(IDBConnection $db)
-// {
-// parent::__construct($db, self::TABLENAME);
-// }
-
-// public function find($id)
-// {
-// $sql = 'SELECT * FROM *PREFIX*' . self::TABLENAME . ' WHERE id = ?';
-// return $this->findEntity($sql, [
-// $id
-// ]);
-// }
-
-// public function findByKey($clef)
-// {
-// $sql = 'SELECT * FROM *PREFIX*' . self::TABLENAME . ' WHERE clef = ?';
-// return $this->findEntity($sql, [
-// $clef
-// ]);
-// }
-
-
-// }
-
diff --git a/lib/Db/Index.php b/lib/Db/LiveQueue.php
index 6371fc6..c7310ef 100644
--- a/lib/Db/Index.php
+++ b/lib/Db/LiveQueue.php
@@ -24,39 +24,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
-// namespace OCA\Nextant\Db;
+namespace OCA\Nextant\Db;
-//
-// We're not using a database yet.
-//
+use \OCA\Nextant\Items\ItemQueue;
+use OCP\AppFramework\Db\Entity;
-// use OCP\AppFramework\Db\Entity;
+class LiveQueue extends Entity
+{
-// class Index extends Entity
-// {
+ public $id;
-// public $id;
+ public $item;
-// // public $userid;
-
-// public $clef;
-
-// // public $path;
-
-// public $creation;
-
-// public function __construct(array $params = [])
-// {
-// $this->addType('id', 'integer');
-
-// if (key_exists('id', $params))
-// $this->setId($params['id']);
-
-// if (key_exists('clef', $params))
-// $this->setClef($params['clef']);
-
-// if (key_exists('creation', $params))
-// $this->setCreation($params['creation']);
-// }
-// }
+ public function __construct($item = null)
+ {
+ $this->setItem(ItemQueue::toJson($item));
+ }
+}
diff --git a/lib/Db/LiveQueueMapper.php b/lib/Db/LiveQueueMapper.php
new file mode 100644
index 0000000..5c35b46
--- /dev/null
+++ b/lib/Db/LiveQueueMapper.php
@@ -0,0 +1,74 @@
+<?php
+
+/**
+ * Nextcloud - nextant
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Maxence Lange <maxence@pontapreta.net>
+ * @copyright Maxence Lange 2016
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OCA\Nextant\Db;
+
+use OCA\Nextant\Db\LiveQueue;
+use \OCA\Nextant\Items\ItemQueue;
+use OCP\IDBConnection;
+use OCP\AppFramework\Db\Mapper;
+
+class LiveQueueMapper extends Mapper
+{
+
+ const TABLENAME = 'nextant_live_queue';
+
+ public function __construct(IDBConnection $db)
+ {
+ parent::__construct($db, self::TABLENAME, 'OCA\Nextant\Db\LiveQueue');
+ }
+
+ public function find($id)
+ {
+ $sql = 'SELECT * FROM *PREFIX*' . self::TABLENAME . ' WHERE id = ?';
+ return $this->findEntity($sql, [
+ $id
+ ]);
+ }
+
+ public function next($keepit = false)
+ {
+ try {
+ $sql = 'SELECT * FROM *PREFIX*' . self::TABLENAME . ' ORDER BY id ASC LIMIT 0, 1';
+ $result = $this->findEntity($sql, []);
+ } catch (\OCP\AppFramework\Db\DoesNotExistException $dnee) {
+ return false;
+ }
+
+ if (! $keepit) {
+ $this->delete($result);
+ }
+
+ return $result;
+ }
+
+ public function clear()
+ {
+ $sql = 'TRUNCATE *PREFIX*' . self::TABLENAME;
+ return $this->execute();
+ }
+}
+
diff --git a/lib/Items/ItemQueue.php b/lib/Items/ItemQueue.php
index 87efcb2..0b996ff 100644
--- a/lib/Items/ItemQueue.php
+++ b/lib/Items/ItemQueue.php
@@ -118,6 +118,8 @@ class ItemQueue
public static function toJson($item)
{
+ if ($item === null)
+ return null;
return json_encode(array(
'type' => $item->getType(),
'userid' => $item->getUserId(),
diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php
index 9fee3b3..4c22626 100644
--- a/lib/Service/ConfigService.php
+++ b/lib/Service/ConfigService.php
@@ -54,6 +54,7 @@ class ConfigService
'resource_level' => '4',
'index_live' => '1',
+ 'index_live_sql' => '1',
'index_live_queuekey' => '19375',
'index_delay' => '2',
'index_locked' => '0',
@@ -193,6 +194,11 @@ class ConfigService
return false;
}
+ /**
+ * returns the current resource level.
+ *
+ * @return number
+ */
public function resourceLevel()
{
return $this->getAppValue('resource_level');
diff --git a/lib/Service/QueueService.php b/lib/Service/QueueService.php
index 325a3c1..2393019 100644
--- a/lib/Service/QueueService.php
+++ b/lib/Service/QueueService.php
@@ -29,6 +29,7 @@ namespace OCA\Nextant\Service;
use \OCA\Nextant\Events\FilesEvents;
use \OCA\Nextant\Items\ItemQueue;
use \OCA\Nextant\Items\ItemDocument;
+use \OCA\Nextant\Db\LiveQueue;
class QueueService
{
@@ -45,24 +46,36 @@ class QueueService
private $queue = null;
- public function __construct($configService, $indexService, $fileService, $miscService)
+ private $parent = null;
+
+ public function __construct($liveQueueMapper, $configService, $indexService, $fileService, $miscService)
{
+ $this->liveQueueMapper = $liveQueueMapper;
$this->configService = $configService;
$this->indexService = $indexService;
$this->fileService = $fileService;
$this->miscService = $miscService;
}
+ public function setParent($parent)
+ {
+ $this->parent = $parent;
+ }
+
public function liveIndex($item)
{
if ($this->configService->getAppValue('index_live') !== '1')
return;
- $queue = msg_get_queue($this->configService->getAppValue('index_live_queuekey'));
- $msg = ItemQueue::toJson($item);
+ if ($this->configService->getAppValue('index_live_sql') === '1')
+ $this->liveQueueMapper->insert(new LiveQueue($item));
- if (! msg_send($queue, 1, $msg))
- $this->miscService->log('can\'t msg_send()');
+ else {
+ $queue = msg_get_queue($this->configService->getAppValue('index_live_queuekey'));
+
+ if (! msg_send($queue, 1, ItemQueue::toJson($item)))
+ $this->miscService->log('can\'t msg_send()');
+ }
}
public function emptyQueue()
@@ -70,7 +83,10 @@ class QueueService
if ($this->configService->getAppValue('index_live') !== '1')
return;
- msg_remove_queue(msg_get_queue($this->configService->getAppValue('index_live_queuekey')));
+ if ($this->configService->getAppValue('index_live_sql') === '1')
+ $this->liveQueueMapper->clear();
+ else
+ msg_remove_queue(msg_get_queue($this->configService->getAppValue('index_live_queuekey')));
}
public function readQueue($standby = false)
@@ -78,25 +94,51 @@ class QueueService
if ($this->configService->getAppValue('index_live') !== '1')
return;
- $queue = msg_get_queue($this->configService->getAppValue('index_live_queuekey'));
-
- $msg_type = NULL;
$msg = NULL;
- $max_msg_size = 512;
-
- $infos = msg_stat_queue($queue);
- if (! $standby && $infos['msg_qnum'] == 0)
- return false;
-
- if (! msg_receive($queue, 1, $msg_type, $max_msg_size, $msg, true, 0, $error)) {
- return false;
+ if ($this->configService->getAppValue('index_live_sql') === '1') {
+
+ while (true) {
+
+ if ($this->parent != null)
+ $this->parent->interrupted();
+
+ $queue = $this->liveQueueMapper->next();
+ if ($queue)
+ break;
+ if (! $standby && ! $queue)
+ break;
+ sleep(15);
+ }
+
+ if ($queue)
+ $msg = $queue->getItem();
+
+ } else {
+ $queue = msg_get_queue($this->configService->getAppValue('index_live_queuekey'));
+
+ $msg_type = NULL;
+ $max_msg_size = 512;
+
+ $infos = msg_stat_queue($queue);
+ if (! $standby && $infos['msg_qnum'] == 0)
+ return false;
+
+ if (! msg_receive($queue, 1, $msg_type, $max_msg_size, $msg, true, 0, $error)) {
+ return false;
+ }
}
+ if ($msg == NULL)
+ return;
+
return ItemQueue::fromJson($msg);
}
public function executeItem($item)
{
+ if ($item == null)
+ return false;
+
$options = array();
if (! $item->getUserId())