Permalink
Browse files

Fixed inefficient code (same count query twice)

  • Loading branch information...
1 parent a74a519 commit 5d06ad52d6d741fc5c1ba624190ad659e70a4752 @seratch seratch committed Mar 8, 2014
Showing with 6 additions and 4 deletions.
  1. +6 −4 framework/src/main/scala/skinny/controller/SkinnyResource.scala
@@ -184,12 +184,14 @@ trait SkinnyResourceActions[Id] { self: SkinnyController =>
*/
def showResources()(implicit format: Format = Format.HTML): Any = withFormat(format) {
if (enablePagination) {
- val pageNo = params.getAs[Int](pageNoParamName).getOrElse(1)
+
+ val pageNo: Int = params.getAs[Int](pageNoParamName).getOrElse(1)
+ val totalCount: Long = model.countAllModels()
+ val totalPages: Int = (totalCount / pageSize).toInt + (if (model.countAllModels() % pageSize == 0) 0 else 1)
+
set(itemsName, model.findModels(pageSize, pageNo))
- val totalPages: Int = (model.countAllModels() / pageSize).toInt + {
- if (model.countAllModels() % pageSize == 0) 0 else 1
- }
set(totalPagesAttributeName -> totalPages)
+
} else {
set(itemsName, model.findAllModels())
}

0 comments on commit 5d06ad5

Please sign in to comment.