-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix 500 server error on project dashboard (#1779)
Large projects were returning an HTTP 500 on the project dashboard, because PHP was running out of memory trying to return every entry for stats to be calculated client-side. This changes the stats to be calculated server-side instead. We get rid of the "number of entries with audio" stat because it's not possible to calculate in a simple Mongo query and would require serializing the entire entry database server-side, causing the very memory error we're trying to get rid of.
- Loading branch information
Showing
5 changed files
with
65 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Api\Model\Languageforge\Lexicon\Dto; | ||
use Api\Model\Shared\Mapper\MongoQueries; | ||
|
||
class LexStatsDto | ||
{ | ||
/** | ||
* @param ProjectModel $project | ||
* @throws \Exception | ||
* @return array | ||
*/ | ||
public static function encode($project) | ||
{ | ||
$db = MongoStore::connect($project->databaseName()); | ||
$num_entries = MongoQueries::countEntries($db, "lexicon"); | ||
$num_entries_with_pictures = MongoQueries::countEntriesWithPictures($db, "lexicon"); | ||
$num_unresolved_comments = MongoQueries::countUnresolvedComments($db, "lexiconComments"); | ||
return [ | ||
"num_entries" => $num_entries, | ||
"num_entries_with_pictures" => $num_entries_with_pictures, | ||
"num_unresolved_comments" => $num_unresolved_comments, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Api\Model\Shared\Mapper; | ||
|
||
class MongoQueries | ||
{ | ||
public static function countEntries($db, $collectionName) | ||
{ | ||
$coll = $db->selectCollection($collectionName); | ||
return $coll->count(); | ||
} | ||
|
||
public static function countEntriesWithPictures($db, $collectionName) | ||
{ | ||
$coll = $db->selectCollection($collectionName); | ||
$query = [ | ||
"senses" => ['$exists' => true, '$ne' => []], | ||
"senses.pictures" => ['$exists' => true, '$ne' => []], | ||
]; | ||
return $coll->count($query); | ||
} | ||
|
||
public static function countUnresolvedComments($db, $collectionName) | ||
{ | ||
$coll = $db->selectCollection($collectionName); | ||
$query = [ | ||
"status" => ['$exists' => true, '$ne' => "resolved"], | ||
]; | ||
return $coll->count($query); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters