Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hack(jerahmeel): force select filter when problem query will be slow #490

Merged
merged 1 commit into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProblemSetProblemInfo>().totalCount(0).build())
.build();
}

Set<String> allowedProblemJids = null;
if (!tags.isEmpty()) {
allowedProblemJids = sandalphonClient.getProblemJidsByTags(tags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public ProblemStore(
this.problemDao = problemDao;
}

public int getTotalProblems() {
return problemDao.select().count();
}

public Page<ProblemSetProblemInfo> getProblems(Set<String> allowedProblemJids, int pageNumber, int pageSize) {
Page<ProblemSetProblemModel> models = problemDao.selectPagedByDifficulty(allowedProblemJids, pageNumber, pageSize);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,23 @@ class ProblemsPage extends Component {
};

renderProblems = () => {
const { response } = this.state;
const { response, filter } = this.state;
if (!response || !response.data) {
return <LoadingState />;
}

const { data: problems, problemsMap, problemMetadatasMap, problemDifficultiesMap, problemProgressesMap } = response;

if (problems.page.length === 0) {
if (filter.tags.length === 0) {
return (
<>
<p>To view problems, select some filters on the left.</p>
<p>We will refine this page in the future.</p>
</>
);
}

return (
<p>
<small>No problems found.</small>
Expand Down