Skip to content

Commit 64c535a

Browse files
max-zillalmarini
andauthored
Do not index datasets & collections in trash (#131)
* Do not index datasets & collections in trash * Omit trashed files from query Co-authored-by: Luigi Marini <[email protected]>
1 parent 4c97cd1 commit 64c535a

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
### Changed
1313
- api/reports/storage/spaces endpoint now accepts a space parameter for ID rather than requiring a space filter.
14+
- Datasets and collections in the trash are no longer indexed for discovery in search services.
1415

1516
## 1.13.0 - 2020-12-02
1617

@@ -40,7 +41,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
4041
### Changed
4142
- Docker Images are now pushed to [github container registry](https://github.com/orgs/clowder-framework/packages)
4243

43-
4444
## 1.12.0 - 2020-10-19
4545
**_Warning:_**
4646
- This update modifies the MongoDB schema. Make sure to start the application with `-DMONGOUPDATE=1`.

app/services/DatasetService.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,4 +385,5 @@ trait DatasetService {
385385

386386
def getIterator(space: Option[String], since: Option[String], until: Option[String]): Iterator[Dataset]
387387

388+
def getTrashedIds(): List[UUID]
388389
}

app/services/mongodb/MongoDBCollectionService.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ class MongoDBCollectionService @Inject() (
894894

895895
def indexAll(idx: Option[String] = None) = {
896896
// Bypass Salat in case any of the file records are malformed to continue past them
897-
Collection.dao.collection.find(MongoDBObject(), MongoDBObject("_id" -> 1)).foreach(c => {
897+
Collection.dao.collection.find(MongoDBObject("trash" -> false), MongoDBObject("_id" -> 1)).foreach(c => {
898898
index(new UUID(c.get("_id").toString), idx)
899899
})
900900
}

app/services/mongodb/MongoDBDatasetService.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ class MongoDBDatasetService @Inject() (
14121412

14131413
def indexAll(idx: Option[String] = None) = {
14141414
// Bypass Salat in case any of the file records are malformed to continue past them
1415-
Dataset.dao.collection.find(MongoDBObject(), MongoDBObject("_id" -> 1)).foreach(d => {
1415+
Dataset.dao.collection.find(MongoDBObject("trash" -> false), MongoDBObject("_id" -> 1)).foreach(d => {
14161416
index(new UUID(d.get("_id").toString), idx)
14171417
})
14181418
}
@@ -1648,6 +1648,16 @@ class MongoDBDatasetService @Inject() (
16481648
until.foreach(t => query = query ++ ("created" $lte Parsers.fromISO8601(t)))
16491649
Dataset.find(query)
16501650
}
1651+
1652+
// Get a list of all trashed dataset and file ids for comparison
1653+
def getTrashedIds(): List[UUID] = {
1654+
val trashedIds = ListBuffer[UUID]()
1655+
Dataset.find(MongoDBObject("trash" -> true)).map(ds => {
1656+
ds.files.foreach(fid => trashedIds += fid)
1657+
trashedIds += ds.id
1658+
})
1659+
trashedIds.toList
1660+
}
16511661
}
16521662

16531663
object Dataset extends ModelCompanion[Dataset, ObjectId] {

app/services/mongodb/MongoDBFileService.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,11 @@ class MongoDBFileService @Inject() (
326326

327327
def indexAll(idx: Option[String] = None) = {
328328
// Bypass Salat in case any of the file records are malformed to continue past them
329+
val trashedIds = datasets.getTrashedIds()
329330
FileDAO.dao.collection.find(MongoDBObject(), MongoDBObject("_id" -> 1)).foreach(f => {
330-
index(new UUID(f.get("_id").toString), idx)
331+
val fid = new UUID(f.get("_id").toString)
332+
if (!trashedIds.contains(fid))
333+
index(fid, idx)
331334
})
332335
}
333336

0 commit comments

Comments
 (0)