-
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
[#12048] Data migration for feedback session entities #12986
[#12048] Data migration for feedback session entities #12986
Conversation
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.
Nice work on this! I've highlighted 2 parts which could be causing verification to be slow
I think in this PR you can uncomment the seed (unless there's a reason) and also optimise your seed script
protected void migrateEntity(FeedbackSession oldEntity) throws Exception { | ||
HibernateUtil.beginTransaction(); | ||
Course course = HibernateUtil.get(teammates.storage.sqlentity.Course.class, oldEntity.getCourseId()); | ||
HibernateUtil.commitTransaction(); |
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.
This transaction is probably causing the migration to be slow, we probably can optimise this by joining courses with its feedback sessions
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.
Changed it to use EntityManager.getReference.
src/client/java/teammates/client/scripts/sql/VerifyFeedbackSessionAttributes.java
Show resolved
Hide resolved
src/client/java/teammates/client/scripts/sql/VerifyFeedbackSessionAttributes.java
Show resolved
Hide resolved
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.
LGTM! Nice work optimising migration using FK
0e31828
to
82d0605
Compare
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.
Other than that, lgtm
getRandomInstant(), | ||
rand.nextInt(3) > 1 ? null : getRandomInstant(), // set deletedAt randomly at 25% chance | ||
false); | ||
ofy().save().entities(course).now(); | ||
} catch (Exception e) { | ||
log(e.toString()); | ||
} | ||
|
||
seedFeedbackSession(courseId); |
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.
Likewise, should this be in the try block? so that if there is an exception then you wont seed the feedback session
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.
In this case I think each seed function should not be catching the error within their own function but throwing to be caught here, let's make a note of this and fix it in another PR to unblock everyone else
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.
Thanks for catching this, i'll change in feedback question pr then.
Part of #12048
Outline of Solution
SeedDb.java
Edit:
Migration script initially took very long due to the need to fetch the course reference and set it in the new feedback session entity.
Added a function
getReference(entity class, id)
inHibernate.util
to use EntityManager.getReference and use this instead of the normalget
. Increased performance from nearly 1 hr to 1 minute for 30K entities.Stats (tested on Google cloud):
@Fetch
annotation) 31.558s (With@Fetch
annotation) TBD, > 30min