Skip to content

Commit

Permalink
[#12048] Add database changes and speed up seeding (#13085)
Browse files Browse the repository at this point in the history
* Add changes

* Speed up seeding
  • Loading branch information
FergusMok committed Apr 24, 2024
1 parent 25a6c91 commit fa8be50
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,25 +202,27 @@ private teammates.storage.sqlentity.Course createCourse(Course oldCourse) {

private teammates.storage.sqlentity.Section createSection(teammates.storage.sqlentity.Course newCourse,
String sectionName) {
// if (sectionName.equals(Const.DEFAULT_SECTION)) {
// return Const.DEFAULT_SQL_SECTION;
// }
Section newSection = new Section(newCourse, sectionName);
String truncatedName = truncateToLength255(sectionName);
Section newSection = new Section(newCourse, truncatedName);
newSection.setCreatedAt(Instant.now());
return newSection;
}

private teammates.storage.sqlentity.Team createTeam(teammates.storage.sqlentity.Section section, String teamName) {
Team newTeam = new teammates.storage.sqlentity.Team(section, teamName);
String truncatedTeamName = truncateToLength255(teamName);
Team newTeam = new teammates.storage.sqlentity.Team(section, truncatedTeamName);
newTeam.setCreatedAt(Instant.now());
return newTeam;
}

private Student createStudent(teammates.storage.sqlentity.Course newCourse,
teammates.storage.sqlentity.Team newTeam,
CourseStudent oldStudent) {
Student newStudent = new Student(newCourse, oldStudent.getName(), oldStudent.getEmail(),
oldStudent.getComments(), newTeam);
String truncatedStudentName = truncateToLength255(oldStudent.getName());
String truncatedComments = truncateToLength2000(oldStudent.getComments());

Student newStudent = new Student(newCourse, truncatedStudentName, oldStudent.getEmail(),
truncatedComments, newTeam);
newStudent.setUpdatedAt(oldStudent.getUpdatedAt());
newStudent.setRegKey(oldStudent.getRegistrationKey());
newStudent.setCreatedAt(oldStudent.getCreatedAt());
Expand Down Expand Up @@ -330,11 +332,13 @@ private void migrateFeedbackResponseComment(teammates.storage.sqlentity.Feedback

private teammates.storage.sqlentity.FeedbackSession createFeedbackSession(teammates.storage.sqlentity.Course newCourse,
FeedbackSession oldSession) {
String truncatedSessionInstructions = truncateToLength2000(oldSession.getInstructions());

teammates.storage.sqlentity.FeedbackSession newSession = new teammates.storage.sqlentity.FeedbackSession(
oldSession.getFeedbackSessionName(),
newCourse,
oldSession.getCreatorEmail(),
oldSession.getInstructions(),
truncatedSessionInstructions,
oldSession.getStartTime(),
oldSession.getEndTime(),
oldSession.getSessionVisibleFromTime(),
Expand Down Expand Up @@ -472,14 +476,16 @@ private FeedbackResponseDetails getFeedbackResponseDetails(FeedbackResponse oldR
private teammates.storage.sqlentity.FeedbackResponseComment createFeedbackResponseComment(
teammates.storage.sqlentity.FeedbackResponse newResponse, FeedbackResponseComment oldComment,
Section giverSection, Section recipientSection) {
String truncatedCommentText = truncateToLength2000(oldComment.getCommentText());

teammates.storage.sqlentity.FeedbackResponseComment newComment =
new teammates.storage.sqlentity.FeedbackResponseComment(
newResponse,
oldComment.getGiverEmail(),
oldComment.getCommentGiverType(),
giverSection,
recipientSection,
oldComment.getCommentText(),
truncatedCommentText,
oldComment.getIsVisibilityFollowingFeedbackQuestion(),
oldComment.getIsCommentFromFeedbackParticipant(),
oldComment.getShowCommentTo(),
Expand Down Expand Up @@ -516,12 +522,15 @@ private teammates.storage.sqlentity.Instructor migrateInstructor(teammates.stora
newPrivileges = new InstructorPrivileges(privilegesLegacy);
}

String truncatedInstructorName = truncateToLength255(oldInstructor.getName());
String truncatedDisplayName = truncateToLength255(oldInstructor.getDisplayedName());

teammates.storage.sqlentity.Instructor newInstructor = new teammates.storage.sqlentity.Instructor(
newCourse,
oldInstructor.getName(),
truncatedInstructorName,
oldInstructor.getEmail(),
oldInstructor.isDisplayedToStudents(),
oldInstructor.getDisplayedName(),
truncatedDisplayName,
InstructorPermissionRole.getEnum(oldInstructor.getRole()),
newPrivileges);

Expand Down Expand Up @@ -755,6 +764,27 @@ private void flushEntitiesSavingBuffer() {
entitiesSavingBuffer.clear();
}

/**
* Truncates a string to a maximum length.
*/
protected String truncate(String str, int maxLength) {
return str.length() > maxLength ? str.substring(0, maxLength) : str;
}

/**
* Truncates to a length of 255.
*/
protected String truncateToLength255(String str) {
return truncate(str, 255);
}

/**
* Truncates to a length of 2000.
*/
protected String truncateToLength2000(String str) {
return truncate(str, 2000);
}

/**
* Logs a comment.
*/
Expand Down
Loading

0 comments on commit fa8be50

Please sign in to comment.