-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
[#11585] Fix unnecessary data read in expected submission count #11659
Merged
wkurniawan07
merged 21 commits into
TEAMMATES:master
from
moziliar:11585-fix-unnecessary-data-read
Mar 28, 2022
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
97a5284
update: add get number of students for course id
moziliar 2646bcb
update: add method to only retrieve instructor emails in a course
moziliar fd9ac58
update: add methods to get aggregate count of questions by giver types
moziliar 08383c7
fix: remove projection query that requires expensive index
moziliar 15533f6
update: change all Long to Int
moziliar 474fecd
nit: change return type to unboxed int
moziliar ffd86ba
nit: change assert false to assert not equal for equality check
moziliar 3129653
nit: change name of var and javadoc to include email
moziliar dfc06d5
nit: fix typo
moziliar fb7e683
Merge branch 'master' into 11585-fix-unnecessary-data-read
moziliar 4041ef8
nit: fix typo
moziliar f3c2edf
nit: change type to int wherever appropriate
moziliar 0c165b2
nit: fix typo and revert unrelated typo fix
moziliar 35a490a
update: use hasQuestionForX in place of counting giver type
moziliar 37dcec8
update: reduce more redundant data read from checking presence of ins…
moziliar 36d95bf
update: reduce data read
moziliar 6692fe9
Merge branch 'master' into 11585-fix-unnecessary-data-read
moziliar c4888b8
refactor: refactor getExpectedTotalSubmission to counting instructor …
moziliar 9e1ff59
refactor: reorder code to make data read only when necessary
moziliar cbcd27f
refactor: remove duplicate condition
moziliar 5473d99
Merge branch 'master' into 11585-fix-unnecessary-data-read
wkurniawan07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ | |
import teammates.common.datatransfer.attributes.FeedbackQuestionAttributes; | ||
import teammates.common.datatransfer.attributes.FeedbackSessionAttributes; | ||
import teammates.common.datatransfer.attributes.InstructorAttributes; | ||
import teammates.common.datatransfer.attributes.StudentAttributes; | ||
import teammates.common.exception.EntityAlreadyExistsException; | ||
import teammates.common.exception.EntityDoesNotExistException; | ||
import teammates.common.exception.InvalidParametersException; | ||
|
@@ -249,12 +248,8 @@ public boolean isFeedbackSessionAttemptedByInstructor(FeedbackSessionAttributes | |
return true; | ||
} | ||
|
||
String feedbackSessionName = fsa.getFeedbackSessionName(); | ||
String courseId = fsa.getCourseId(); | ||
List<FeedbackQuestionAttributes> allQuestions = | ||
fqLogic.getFeedbackQuestionsForInstructors(feedbackSessionName, courseId, userEmail); | ||
// if there is no question for instructor, session is attempted | ||
return allQuestions.isEmpty(); | ||
return !fqLogic.hasFeedbackQuestionsForInstructors(fsa, fsa.isCreator(userEmail)); | ||
} | ||
|
||
/** | ||
|
@@ -492,24 +487,31 @@ public void restoreFeedbackSessionFromRecycleBin(String feedbackSessionName, Str | |
* Gets the expected number of submissions for a feedback session. | ||
*/ | ||
public int getExpectedTotalSubmission(FeedbackSessionAttributes fsa) { | ||
List<StudentAttributes> students = studentsLogic.getStudentsForCourse(fsa.getCourseId()); | ||
List<InstructorAttributes> instructors = instructorsLogic.getInstructorsForCourse(fsa.getCourseId()); | ||
List<FeedbackQuestionAttributes> questions = | ||
fqLogic.getFeedbackQuestionsForSession(fsa.getFeedbackSessionName(), fsa.getCourseId()); | ||
List<FeedbackQuestionAttributes> studentQns = fqLogic.getFeedbackQuestionsForStudents(questions); | ||
|
||
int expectedTotal = 0; | ||
|
||
if (!studentQns.isEmpty()) { | ||
expectedTotal += students.size(); | ||
if (fqLogic.hasFeedbackQuestionsForStudents(fsa)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wkurniawan07 Totally refactored this method. It works on the assumption that |
||
expectedTotal += studentsLogic.getNumberOfStudentsForCourse(fsa.getCourseId()); | ||
} | ||
|
||
for (InstructorAttributes instructor : instructors) { | ||
List<FeedbackQuestionAttributes> instructorQns = | ||
fqLogic.getFeedbackQuestionsForInstructors(questions, fsa.isCreator(instructor.getEmail())); | ||
if (!instructorQns.isEmpty()) { | ||
expectedTotal += 1; | ||
} | ||
// Pre-flight check to ensure there are questions for instructors. | ||
if (!fqLogic.hasFeedbackQuestionsForInstructors(fsa, true)) { | ||
return expectedTotal; | ||
} | ||
|
||
List<String> instructorEmails = instructorsLogic.getInstructorEmailsForCourse(fsa.getCourseId()); | ||
if (instructorEmails.isEmpty()) { | ||
return expectedTotal; | ||
} | ||
|
||
// Check presence of questions for instructors. | ||
if (fqLogic.hasFeedbackQuestionsForInstructors(fsa, false)) { | ||
expectedTotal += instructorEmails.size(); | ||
} else { | ||
// No questions for instructors. There must be questions for creator. | ||
List<String> creatorEmails = instructorEmails.stream() | ||
.filter(fsa::isCreator) | ||
.collect(Collectors.toList()); | ||
expectedTotal += creatorEmails.size(); | ||
} | ||
|
||
return expectedTotal; | ||
|
@@ -566,8 +568,8 @@ public boolean isFeedbackSessionForUserTypeToAnswer(FeedbackSessionAttributes se | |
} | ||
|
||
return isInstructor | ||
? fqLogic.hasFeedbackQuestionsForInstructors(session.getFeedbackSessionName(), session.getCourseId(), null) | ||
: fqLogic.hasFeedbackQuestionsForStudents(session.getFeedbackSessionName(), session.getCourseId()); | ||
? fqLogic.hasFeedbackQuestionsForInstructors(session, false) | ||
: fqLogic.hasFeedbackQuestionsForStudents(session); | ||
} | ||
|
||
} |
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One suggestion is perhaps use
doesIncludeCreator
given the context of this method?isCreator