From f0b1b2ffcede6bd1af5d76dfc01cc13050d3ca72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20B=C3=BC=C3=9Femeyer?= Date: Thu, 28 Nov 2024 14:08:57 +0100 Subject: [PATCH] add debug logging for dataset list route --- app/controllers/DatasetController.scala | 78 +++++++++++++------------ app/models/dataset/Dataset.scala | 14 +++-- 2 files changed, 51 insertions(+), 41 deletions(-) diff --git a/app/controllers/DatasetController.scala b/app/controllers/DatasetController.scala index f7c600459db..6c770762481 100755 --- a/app/controllers/DatasetController.scala +++ b/app/controllers/DatasetController.scala @@ -176,42 +176,48 @@ class DatasetController @Inject()(userService: UserService, // Change output format to return only a compact list with essential information on the datasets compact: Option[Boolean] ): Action[AnyContent] = sil.UserAwareAction.async { implicit request => - for { - folderIdValidated <- Fox.runOptional(folderId)(ObjectId.fromString) - uploaderIdValidated <- Fox.runOptional(uploaderId)(ObjectId.fromString) - organizationIdOpt = if (onlyMyOrganization.getOrElse(false)) - request.identity.map(_._organization) - else - organizationId - js <- if (compact.getOrElse(false)) { - for { - datasetInfos <- datasetDAO.findAllCompactWithSearch( - isActive, - isUnreported, - organizationIdOpt, - folderIdValidated, - uploaderIdValidated, - searchQuery, - request.identity.map(_._id), - recursive.getOrElse(false), - limitOpt = limit - ) - } yield Json.toJson(datasetInfos) - } else { - for { - datasets <- datasetDAO.findAllWithSearch(isActive, - isUnreported, - organizationIdOpt, - folderIdValidated, - uploaderIdValidated, - searchQuery, - recursive.getOrElse(false), - limit) ?~> "dataset.list.failed" - js <- listGrouped(datasets, request.identity) ?~> "dataset.list.failed" - } yield Json.toJson(js) - } - _ = Fox.runOptional(request.identity)(user => userDAO.updateLastActivity(user._id)) - } yield addRemoteOriginHeaders(Ok(js)) + log() { + for { + folderIdValidated <- Fox.runOptional(folderId)(ObjectId.fromString) + uploaderIdValidated <- Fox.runOptional(uploaderId)(ObjectId.fromString) + organizationIdOpt = if (onlyMyOrganization.getOrElse(false)) + request.identity.map(_._organization) + else + organizationId + js <- if (compact.getOrElse(false)) { + for { + datasetInfos <- datasetDAO.findAllCompactWithSearch( + isActive, + isUnreported, + organizationIdOpt, + folderIdValidated, + uploaderIdValidated, + searchQuery, + request.identity.map(_._id), + recursive.getOrElse(false), + limitOpt = limit + ) + } yield Json.toJson(datasetInfos) + } else { + for { + _ <- Fox.successful(()) + _ = logger.info( + s"Requesting listing datasets with isActive '$isActive', isUnreported '$isUnreported', organizationId '$organizationIdOpt', folderId '$folderIdValidated', uploaderId '$uploaderIdValidated', searchQuery '$searchQuery', recursive '$recursive', limit '$limit'") + datasets <- datasetDAO.findAllWithSearch(isActive, + isUnreported, + organizationIdOpt, + folderIdValidated, + uploaderIdValidated, + searchQuery, + recursive.getOrElse(false), + limit) ?~> "dataset.list.failed" ?~> "Dataset listing failed" + _ = logger.info(s"Found ${datasets.size} datasets successfully") + js <- listGrouped(datasets, request.identity) ?~> "dataset.list.failed" ?~> "Grouping datasets failed" + } yield Json.toJson(js) + } + _ = Fox.runOptional(request.identity)(user => userDAO.updateLastActivity(user._id)) + } yield addRemoteOriginHeaders(Ok(js)) + } } private def listGrouped(datasets: List[Dataset], requestingUser: Option[User])( diff --git a/app/models/dataset/Dataset.scala b/app/models/dataset/Dataset.scala index ebfa63387a1..bb6feade662 100755 --- a/app/models/dataset/Dataset.scala +++ b/app/models/dataset/Dataset.scala @@ -115,12 +115,14 @@ class DatasetDAO @Inject()(sqlClient: SqlClient, datasetLayerDAO: DatasetLayerDA protected def parse(r: DatasetsRow): Fox[Dataset] = for { - voxelSize <- parseVoxelSizeOpt(r.voxelsizefactor, r.voxelsizeunit) + voxelSize <- parseVoxelSizeOpt(r.voxelsizefactor, r.voxelsizeunit) ?~> "could not parse dataset voxel size" defaultViewConfigurationOpt <- Fox.runOptional(r.defaultviewconfiguration)( - JsonHelper.parseAndValidateJson[DatasetViewConfiguration](_)) + JsonHelper + .parseAndValidateJson[DatasetViewConfiguration](_)) ?~> "could not parse dataset default view configuration" adminViewConfigurationOpt <- Fox.runOptional(r.adminviewconfiguration)( - JsonHelper.parseAndValidateJson[DatasetViewConfiguration](_)) - metadata <- JsonHelper.parseAndValidateJson[JsArray](r.metadata) + JsonHelper + .parseAndValidateJson[DatasetViewConfiguration](_)) ?~> "could not parse dataset admin view configuration" + metadata <- JsonHelper.parseAndValidateJson[JsArray](r.metadata) ?~> "could not parse dataset metadata" } yield { Dataset( ObjectId(r._Id), @@ -218,9 +220,11 @@ class DatasetDAO @Inject()(sqlClient: SqlClient, datasetLayerDAO: DatasetLayerDA includeSubfolders, None, None) + _ = logger.info(s"Requesting datasets with selection predicates '$selectionPredicates'") limitQuery = limitOpt.map(l => q"LIMIT $l").getOrElse(q"") + _ = logger.info("Requesting datasets with query") r <- run(q"SELECT $columns FROM $existingCollectionName WHERE $selectionPredicates $limitQuery".as[DatasetsRow]) - parsed <- parseAll(r) + parsed <- parseAll(r) ?~> "Parsing datasets failed" } yield parsed def findAllCompactWithSearch(isActiveOpt: Option[Boolean] = None,