Index: class.UserStats.php
===================================================================
--- class.UserStats.php	(revision 70)
+++ class.UserStats.php	(working copy)
@@ -87,39 +87,35 @@
 		// - Count different reading states
 
 		// ShelvedBooks
-		$shelvedBookQuery = XN_Query::create('Content')
+        	$shelvedBookQuery = XN_Query::create('Content')
 			->filter('owner')
 			->filter('type', 'eic', "ShelvedBook")
 			->filter('contributorName', '=', $user)
+			->begin(0)->end(1)
 			->alwaysReturnTotalCount();
 		$shelvedBooks = $shelvedBookQuery->execute();
 		$shelvedBookCount = $shelvedBookQuery->getTotalCount();
-		$currentlyReadingCount = 0;
-		$finishedReadingCount = 0;
-		$wantToReadCount = 0;
-		foreach($shelvedBooks as $shelvedBook) {
-			switch($shelvedBook->my->readingState) {
-				case Book::CURRENTLY_READING:
-					++$currentlyReadingCount;
-					break;
-				case Book::FINISHED_READING:
-					++$finishedReadingCount;
-					break;
-				case Book::WANT_TO_READ:
-					++$wantToReadCount;
-					break;
-				default:
-					break;
-			}
-		}
+		$bookCounts = array();
+        	foreach(array(Book::CURRENTLY_READING, Book::FINISHED_READING, Book::WANT_TO_READ) as $v) {
+        
+            	    $shelvedBookQuery = XN_Query::create('Content')
+		    	->filter('owner')
+		    	->filter('type', 'eic', "ShelvedBook")
+		    	->filter('contributorName', '=', $user)
+		    	->filter('my->readingState', '=', $v)
+		    	->begin(0)->end(1)
+		    	->alwaysReturnTotalCount();
+		    $shelvedBooks = $shelvedBookQuery->execute();
+		    $bookCounts[$v] = $shelvedBookQuery->getTotalCount();
+        	}
 
 		// Make the new UsersStats object
 		$stats = XN_Content::create('UserStats', "Statistics of use for this user");
 		$stats->my->shelfOwner = $user;
 		$stats->my->shelvedBookCount = $shelvedBookCount;
-		$stats->my->currentlyReadingCount = $currentlyReadingCount;
-		$stats->my->finishedReadingCount = $finishedReadingCount;
-		$stats->my->wantToReadCount = $wantToReadCount;
+		$stats->my->currentlyReadingCount = $bookCounts[Book::CURRENTLY_READING];
+		$stats->my->finishedReadingCount = $bookCounts[Book::FINISHED_READING];
+		$stats->my->wantToReadCount = $bookCounts[Book::WANT_TO_READ];
 		$stats->isPrivate = true;
 		$stats->save();
 
