diff --git a/judgels-backends/judgels-server-app/src/main/java/judgels/jerahmeel/problem/ProblemResource.java b/judgels-backends/judgels-server-app/src/main/java/judgels/jerahmeel/problem/ProblemResource.java index 74b64c19c..7f9b5302f 100644 --- a/judgels-backends/judgels-server-app/src/main/java/judgels/jerahmeel/problem/ProblemResource.java +++ b/judgels-backends/judgels-server-app/src/main/java/judgels/jerahmeel/problem/ProblemResource.java @@ -45,6 +45,14 @@ public ProblemsResponse getProblems( String actorJid = actorChecker.check(authHeader); + // HACK: the query is very slow. In the meantime, when the number of problems is large, + // we return empty and force the user to filter by tags. + if (tags.isEmpty() && problemStore.getTotalProblems() > 1000) { + return new ProblemsResponse.Builder() + .data(new Page.Builder().totalCount(0).build()) + .build(); + } + Set allowedProblemJids = null; if (!tags.isEmpty()) { allowedProblemJids = sandalphonClient.getProblemJidsByTags(tags); diff --git a/judgels-backends/judgels-server-app/src/main/java/judgels/jerahmeel/problem/ProblemStore.java b/judgels-backends/judgels-server-app/src/main/java/judgels/jerahmeel/problem/ProblemStore.java index 7736b8b46..6882c062f 100644 --- a/judgels-backends/judgels-server-app/src/main/java/judgels/jerahmeel/problem/ProblemStore.java +++ b/judgels-backends/judgels-server-app/src/main/java/judgels/jerahmeel/problem/ProblemStore.java @@ -24,6 +24,10 @@ public ProblemStore( this.problemDao = problemDao; } + public int getTotalProblems() { + return problemDao.select().count(); + } + public Page getProblems(Set allowedProblemJids, int pageNumber, int pageSize) { Page models = problemDao.selectPagedByDifficulty(allowedProblemJids, pageNumber, pageSize); diff --git a/judgels-client/src/routes/problems/problems/ProblemsPage/ProblemsPage.jsx b/judgels-client/src/routes/problems/problems/ProblemsPage/ProblemsPage.jsx index 8ffe22a99..2aff8d221 100644 --- a/judgels-client/src/routes/problems/problems/ProblemsPage/ProblemsPage.jsx +++ b/judgels-client/src/routes/problems/problems/ProblemsPage/ProblemsPage.jsx @@ -52,7 +52,7 @@ class ProblemsPage extends Component { }; renderProblems = () => { - const { response } = this.state; + const { response, filter } = this.state; if (!response || !response.data) { return ; } @@ -60,6 +60,15 @@ class ProblemsPage extends Component { const { data: problems, problemsMap, problemMetadatasMap, problemDifficultiesMap, problemProgressesMap } = response; if (problems.page.length === 0) { + if (filter.tags.length === 0) { + return ( + <> +

To view problems, select some filters on the left.

+

We will refine this page in the future.

+ + ); + } + return (

No problems found.