summaryrefslogtreecommitdiffstats
path: root/lib/private/LanguageModel/Db
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/LanguageModel/Db')
-rw-r--r--lib/private/LanguageModel/Db/Task.php10
-rw-r--r--lib/private/LanguageModel/Db/TaskMapper.php18
2 files changed, 26 insertions, 2 deletions
diff --git a/lib/private/LanguageModel/Db/Task.php b/lib/private/LanguageModel/Db/Task.php
index fe77d559530..895969e08bb 100644
--- a/lib/private/LanguageModel/Db/Task.php
+++ b/lib/private/LanguageModel/Db/Task.php
@@ -8,6 +8,8 @@ use OCP\LanguageModel\ILanguageModelTask;
/**
* @method setType(string $type)
* @method string getType()
+ * @method setLastUpdated(int $lastUpdated)
+ * @method int getLastUpdated()
* @method setInput(string $type)
* @method string getInput()
* @method setStatus(int $type)
@@ -18,6 +20,8 @@ use OCP\LanguageModel\ILanguageModelTask;
* @method string getAppId()
*/
class Task extends Entity {
+ protected $lastUpdated;
+
protected $type;
protected $input;
protected $status;
@@ -27,17 +31,18 @@ class Task extends Entity {
/**
* @var string[]
*/
- public static array $columns = ['id', 'type', 'input', 'output', 'status', 'user_id', 'app_id'];
+ public static array $columns = ['id', 'last_updated', 'type', 'input', 'output', 'status', 'user_id', 'app_id'];
/**
* @var string[]
*/
- public static array $fields = ['id', 'type', 'input', 'output', 'status', 'userId', 'appId'];
+ public static array $fields = ['id', 'lastUpdated', 'type', 'input', 'output', 'status', 'userId', 'appId'];
public function __construct() {
// add types in constructor
$this->addType('id', 'integer');
+ $this->addType('lastUpdated', 'integer');
$this->addType('type', 'string');
$this->addType('input', 'string');
$this->addType('status', 'integer');
@@ -48,6 +53,7 @@ class Task extends Entity {
public static function fromLanguageModelTask(ILanguageModelTask $task): Task {
return Task::fromParams([
'type' => $task->getType(),
+ 'lastUpdated' => time(),
'status' => $task->getStatus(),
'input' => $task->getInput(),
'output' => $task->getOutput(),
diff --git a/lib/private/LanguageModel/Db/TaskMapper.php b/lib/private/LanguageModel/Db/TaskMapper.php
index d7122ea7941..e0b06a1b62b 100644
--- a/lib/private/LanguageModel/Db/TaskMapper.php
+++ b/lib/private/LanguageModel/Db/TaskMapper.php
@@ -3,6 +3,7 @@
namespace OC\LanguageModel\Db;
use OCP\AppFramework\Db\DoesNotExistException;
+use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\Exception;
@@ -30,4 +31,21 @@ class TaskMapper extends QBMapper {
->where($qb->expr()->eq('id', $qb->createPositionalParameter($id)));
return $this->findEntity($qb);
}
+
+ /**
+ * @param int $timeout
+ * @return int the number of deleted tasks
+ * @throws Exception
+ */
+ public function deleteOlderThan(int $timeout): int {
+ $qb = $this->db->getQueryBuilder();
+ $qb->delete($this->tableName)
+ ->where($qb->expr()->lt('last_updated', $qb->createPositionalParameter(time() - $timeout)));
+ return $qb->executeStatement();
+ }
+
+ public function update(Entity $entity): Entity {
+ $entity->setLastUpdated(time());
+ return parent::update($entity);
+ }
}