Replace hardcoded number by a config value

This commit is contained in:
Eike Kettner 2020-06-14 00:48:19 +02:00
parent 479a341b13
commit e15e2c9313
5 changed files with 31 additions and 5 deletions

View File

@ -17,6 +17,13 @@ docspell.server {
port = 7880 port = 7880
} }
# This is a hard limit to restrict the size of a batch that is
# returned when searching for items. The user can set this limit
# within the client config, but it is restricted by the server to
# the number defined here. An admin might choose a lower number
# depending on the available resources.
max-item-page-size = 500
# Authentication. # Authentication.
auth { auth {

View File

@ -12,7 +12,8 @@ case class Config(
bind: Config.Bind, bind: Config.Bind,
backend: BackendConfig, backend: BackendConfig,
auth: Login.Config, auth: Login.Config,
integrationEndpoint: Config.IntegrationEndpoint integrationEndpoint: Config.IntegrationEndpoint,
maxItemPageSize: Int
) )
object Config { object Config {

View File

@ -69,7 +69,7 @@ object RestServer {
"user" -> UserRoutes(restApp.backend, token), "user" -> UserRoutes(restApp.backend, token),
"collective" -> CollectiveRoutes(restApp.backend, token), "collective" -> CollectiveRoutes(restApp.backend, token),
"queue" -> JobQueueRoutes(restApp.backend, token), "queue" -> JobQueueRoutes(restApp.backend, token),
"item" -> ItemRoutes(restApp.backend, token), "item" -> ItemRoutes(cfg, restApp.backend, token),
"attachment" -> AttachmentRoutes(restApp.backend, token), "attachment" -> AttachmentRoutes(restApp.backend, token),
"upload" -> UploadRoutes.secured(restApp.backend, cfg, token), "upload" -> UploadRoutes.secured(restApp.backend, cfg, token),
"checkfile" -> CheckFileRoutes.secured(restApp.backend, token), "checkfile" -> CheckFileRoutes.secured(restApp.backend, token),

View File

@ -13,12 +13,17 @@ import org.http4s.circe.CirceEntityDecoder._
import docspell.restapi.model._ import docspell.restapi.model._
import docspell.common.syntax.all._ import docspell.common.syntax.all._
import docspell.restserver.conv.Conversions import docspell.restserver.conv.Conversions
import docspell.restserver.Config
import org.log4s._ import org.log4s._
object ItemRoutes { object ItemRoutes {
private[this] val logger = getLogger private[this] val logger = getLogger
def apply[F[_]: Effect](backend: BackendApp[F], user: AuthToken): HttpRoutes[F] = { def apply[F[_]: Effect](
cfg: Config,
backend: BackendApp[F],
user: AuthToken
): HttpRoutes[F] = {
val dsl = new Http4sDsl[F] {} val dsl = new Http4sDsl[F] {}
import dsl._ import dsl._
@ -31,7 +36,7 @@ object ItemRoutes {
_ <- logger.ftrace(s"Running query: $query") _ <- logger.ftrace(s"Running query: $query")
items <- backend.item.findItems( items <- backend.item.findItems(
query, query,
Batch(mask.offset, mask.limit).restrictLimitTo(500) Batch(mask.offset, mask.limit).restrictLimitTo(cfg.maxItemPageSize)
) )
resp <- Ok(Conversions.mkItemList(items)) resp <- Ok(Conversions.mkItemList(items))
} yield resp } yield resp
@ -44,7 +49,7 @@ object ItemRoutes {
_ <- logger.ftrace(s"Running query: $query") _ <- logger.ftrace(s"Running query: $query")
items <- backend.item.findItemsWithTags( items <- backend.item.findItemsWithTags(
query, query,
Batch(mask.offset, mask.limit).restrictLimitTo(500) Batch(mask.offset, mask.limit).restrictLimitTo(cfg.maxItemPageSize)
) )
resp <- Ok(Conversions.mkItemListWithTags(items)) resp <- Ok(Conversions.mkItemListWithTags(items))
} yield resp } yield resp

View File

@ -13,6 +13,7 @@ let
app-name = "Docspell"; app-name = "Docspell";
app-id = "rest1"; app-id = "rest1";
base-url = "http://localhost:7880"; base-url = "http://localhost:7880";
max-item-page-size = 500;
bind = { bind = {
address = "localhost"; address = "localhost";
port = 7880; port = 7880;
@ -100,6 +101,18 @@ in {
''; '';
}; };
max-item-page-size = mkOption {
type = types.int;
default = defaults.max-item-page-size;
description = ''
This is a hard limit to restrict the size of a batch that is
returned when searching for items. The user can set this limit
within the client config, but it is restricted by the server to
the number defined here. An admin might choose a lower number
depending on the available resources.
'';
};
bind = mkOption { bind = mkOption {
type = types.submodule({ type = types.submodule({
options = { options = {