Skip to content

Commit

Permalink
don't validate indexes if there are no indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
jliszka committed Aug 6, 2012
1 parent 8efd61d commit 8694eb2
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ object MongoIndexChecker {

/**
* Retrieves the list of indexes declared for the record type associated with a
* query. If the record type doesn't declare any indexes, then returns an empty list.
* query. If the record type doesn't declare any indexes, then returns None.
* @param query the query
* @return the list of indexes, or an empty list.
*/
def getIndexes(query: Query[_, _, _]): List[MongoIndex[_]] = {
def getIndexes(query: Query[_, _, _]): Option[List[MongoIndex[_]]] = {
val queryMetaRecord = query.meta
if (queryMetaRecord.isInstanceOf[IndexedRecord[_]]) {
queryMetaRecord.asInstanceOf[IndexedRecord[_]].mongoIndexList
Some(queryMetaRecord.asInstanceOf[IndexedRecord[_]].mongoIndexList)
} else {
List()
None
}
}

Expand All @@ -61,8 +61,9 @@ object MongoIndexChecker {
* @return true if the required indexes are found, false otherwise.
*/
def validateIndexExpectations(query: Query[_, _, _]): Boolean = {
val indexes = getIndexes(query)
validateIndexExpectations(query, indexes)
getIndexes(query).forall(indexes =>
validateIndexExpectations(query, indexes)
)
}

/**
Expand Down Expand Up @@ -106,8 +107,9 @@ object MongoIndexChecker {
* @param query the query
*/
def validateQueryMatchesSomeIndex(query: Query[_, _, _]): Boolean = {
val indexes = getIndexes(query)
validateQueryMatchesSomeIndex(query, indexes)
getIndexes(query).forall(indexes =>
validateQueryMatchesSomeIndex(query, indexes)
)
}

/**
Expand Down

0 comments on commit 8694eb2

Please sign in to comment.