Improve database usage by consolidating and removing database calls#1585
Improve database usage by consolidating and removing database calls#1585pstaabp merged 10 commits intoopenwebwork:developfrom
Conversation
lib/WeBWorK/DB/. Also update the copyright years and project url, and delete the CVSHeader in those files.
Remove the protection in UserDetail.pm against showing more than 150 sets. That protection wasn't working.
|
I'm getting an error on the Email page (SendMail.pm L#138-47): Which is somewhat strange, given that a similar WHERE clause is used elsewhere (e.g. StudentProgress) and I don't see errors there. |
|
It isn't odd. You don't have viewable_sections or viewable_recitations arrays defined, and I forgot to add the protection about that here. I added it on line 350 of StudentProgress.pm, but forgot it here. |
|
Thanks for testing and finding that. It is fixed now. |
|
I think you committed some other changes ... ceed876 modifies UserDetail.pm |
ceed876 to
9a6c4b4
Compare
|
Oops. Did not want |
|
Ahh, I didn't use |
|
Also, I force pushed that fix. |
|
That worked, the email page now loads without error. 👍 |
are not defined, then the or in the where clause is not added.
c47544a to
c3e3d9a
Compare
that are like the versioned naming scheme in ProblemSetDetail.pm.
c3e3d9a to
0da992d
Compare
makes it possible to delete quiz versions (manually in the database at this point), and the table will still properly display all existing versions even if the numbering is not consecutive.
This has been requested in the forums (see for instance https://webwork.maa.org/moodle/mod/forum/discuss.php?d=2400), and is something that I would also find useful. In my classes I have quizzes that allow three versions with one submission per version, and show only one problem per page. Students frequently will start one version, and then accidentally hit "Grade Test" after only working one problem. This wastes one of the versions for this student. Prior to this pull request I could do this, but had to do so manually by deleting the version and problems in the database. Note that doing so also does not cause problems anywhere else. Note that prior to pull request openwebwork#1585 there was a minor glitch caused on the user detail page if a version was deleted that was not the last version that exists. (This frequently happens because not only do students accidentally hit submit, but then they go start another version before contacting me to fix the problem.) The glitch was caused by the assumption that the version_id stored in the database coincided with array indices (offset by one) in the array of versioned user sets obtained by listing all versions in the database. That of course is not the case with openwebwork#1585. I have been deleting versions manually for years with no issues other than this one. This adds a checkbox to the quiz versions on the user detail page (which you can get to by clicking on the assigned sets for a user in the class list editor). If this checkbox is unchecked, then that specific version of the gateway quiz will be deleted for that user. Note that javascript is used to make the server side behavior clear to the user. If the template set is unchecked, then all of the versions are unchecked as in addition to the template set being unassigned, the versions will all be deleted. If a version is checked (after previously being unchecked) then it is ensured that the template set is also checked. Since this adds a javascript file for the UserDetail.pm module, all of the inline javascript in that file is also moved into the javascript file (the change, blur, and keyup handlers for the date inputs, and the click handler for the "Assign All Sets to Current User" button).
This has been requested in the forums (see for instance https://webwork.maa.org/moodle/mod/forum/discuss.php?d=2400), and is something that I would also find useful. In my classes I have quizzes that allow three versions with one submission per version, and show only one problem per page. Students frequently will start one version, and then accidentally hit "Grade Test" after only working one problem. This wastes one of the versions for this student. Prior to this pull request I could do this, but had to do so manually by deleting the version and problems in the database. Note that doing so also does not cause problems anywhere else. Note that prior to pull request openwebwork#1585 there was a minor glitch caused on the user detail page if a version was deleted that was not the last version that exists. (This frequently happens because not only do students accidentally hit submit, but then they go start another version before contacting me to fix the problem.) The glitch was caused by the assumption that the version_id stored in the database coincided with array indices (offset by one) in the array of versioned user sets obtained by listing all versions in the database. That of course is not the case with openwebwork#1585. I have been deleting versions manually for years with no issues other than this one. This adds a checkbox to the quiz versions on the user detail page (which you can get to by clicking on the assigned sets for a user in the class list editor). If this checkbox is unchecked, then that specific version of the gateway quiz will be deleted for that user. Note that javascript is used to make the server side behavior clear to the user. If the template set is unchecked, then all of the versions are unchecked as in addition to the template set being unassigned, the versions will all be deleted. If a version is checked (after previously being unchecked) then it is ensured that the template set is also checked. Since this adds a javascript file for the UserDetail.pm module, all of the inline javascript in that file is also moved into the javascript file (the change, blur, and keyup handlers for the date inputs, and the click handler for the "Assign All Sets to Current User" button).
the same way on the UserDetail.pm page. The alphabetic sort use for the merged set versions of course will not match the numeric sort used for the set versions. If only the merged set versions were implemented in the same way as the set versions...
This has been requested in the forums (see for instance https://webwork.maa.org/moodle/mod/forum/discuss.php?d=2400), and is something that I would also find useful. In my classes I have quizzes that allow three versions with one submission per version, and show only one problem per page. Students frequently will start one version, and then accidentally hit "Grade Test" after only working one problem. This wastes one of the versions for this student. Prior to this pull request I could do this, but had to do so manually by deleting the version and problems in the database. Note that doing so also does not cause problems anywhere else. Note that prior to pull request openwebwork#1585 there was a minor glitch caused on the user detail page if a version was deleted that was not the last version that exists. (This frequently happens because not only do students accidentally hit submit, but then they go start another version before contacting me to fix the problem.) The glitch was caused by the assumption that the version_id stored in the database coincided with array indices (offset by one) in the array of versioned user sets obtained by listing all versions in the database. That of course is not the case with openwebwork#1585. I have been deleting versions manually for years with no issues other than this one. This adds a checkbox to the quiz versions on the user detail page (which you can get to by clicking on the assigned sets for a user in the class list editor). If this checkbox is unchecked, then that specific version of the gateway quiz will be deleted for that user. Note that javascript is used to make the server side behavior clear to the user. If the template set is unchecked, then all of the versions are unchecked as in addition to the template set being unassigned, the versions will all be deleted. If a version is checked (after previously being unchecked) then it is ensured that the template set is also checked. Since this adds a javascript file for the UserDetail.pm module, all of the inline javascript in that file is also moved into the javascript file (the change, blur, and keyup handlers for the date inputs, and the click handler for the "Assign All Sets to Current User" button).
|
Overall, this looks good. I'm trying to test everything, since this seems to touch nearly every part of webwork. Since you mention speed up, I've noticed that the Homework Sets Editor still loads slowly compared to others and I only really notice it when I have caching turned off. I haven't dug into what might be causing it. Was there anything in here that should speed this up? |
|
I have noticed that as well. I am still looking into that. The thing is that that page loads more data from the database than any other. It doesn't do so very efficiently, but to make it so will require quite the rewrite. |
This has been requested in the forums (see for instance https://webwork.maa.org/moodle/mod/forum/discuss.php?d=2400), and is something that I would also find useful. In my classes I have quizzes that allow three versions with one submission per version, and show only one problem per page. Students frequently will start one version, and then accidentally hit "Grade Test" after only working one problem. This wastes one of the versions for this student. Prior to this pull request I could do this, but had to do so manually by deleting the version and problems in the database. Note that doing so also does not cause problems anywhere else. Note that prior to pull request openwebwork#1585 there was a minor glitch caused on the user detail page if a version was deleted that was not the last version that exists. (This frequently happens because not only do students accidentally hit submit, but then they go start another version before contacting me to fix the problem.) The glitch was caused by the assumption that the version_id stored in the database coincided with array indices (offset by one) in the array of versioned user sets obtained by listing all versions in the database. That of course is not the case with openwebwork#1585. I have been deleting versions manually for years with no issues other than this one. This adds a checkbox to the quiz versions on the user detail page (which you can get to by clicking on the assigned sets for a user in the class list editor). If this checkbox is unchecked, then that specific version of the gateway quiz will be deleted for that user. Note that javascript is used to make the server side behavior clear to the user. If the template set is unchecked, then all of the versions are unchecked as in addition to the template set being unassigned, the versions will all be deleted. If a version is checked (after previously being unchecked) then it is ensured that the template set is also checked. Since this adds a javascript file for the UserDetail.pm module, all of the inline javascript in that file is also moved into the javascript file (the change, blur, and keyup handlers for the date inputs, and the click handler for the "Assign All Sets to Current User" button).
2003c7f to
55bc9fa
Compare
drdrew42
left a comment
There was a problem hiding this comment.
Everything seems to be running smoothly
Every time the Homework Sets Editor loads it combs through the entire templates directory tree looking for def files, including the OPL and Contrib. Depending on how fast your storage is this can greatly slow down the page load. |
|
@dlglin: I just did some timing of things, and came to exactly that conclusion. It is not a database query, it is line 1269 of ProblemSetList.pm that is causing the slow down, and that is the line that does what you say. That is the line number it is on in this pull request (not develop). |
sorting in the database. This was not included in openwebwork#1585 because I didn't want to cause merge conflicts with openwebwork#1569. The file is also cleaned up a bit and the gateway versions listing and homework problem listing sections separated in a more logical and readable way. Those sections were perltidied.
sorting in the database. This was not included in openwebwork#1585 because I didn't want to cause merge conflicts with openwebwork#1569. The file is also cleaned up a bit and the gateway versions listing and homework problem listing sections separated in a more logical and readable way. Those sections were perltidied.
sorting in the database. This was not included in openwebwork#1585 because I didn't want to cause merge conflicts with openwebwork#1569. The file is also cleaned up a bit and the gateway versions listing and homework problem listing sections separated in a more logical and readable way. Those sections were perltidied.
sorting in the database. This was not included in openwebwork#1585 because I didn't want to cause merge conflicts with openwebwork#1569. The file is also cleaned up a bit and the gateway versions listing and homework problem listing sections separated in a more logical and readable way. Those sections were perltidied.
sorting in the database. This was not included in openwebwork#1585 because I didn't want to cause merge conflicts with openwebwork#1569. The file is also cleaned up a bit and the gateway versions listing and homework problem listing sections separated in a more logical and readable way. Those sections were perltidied.
sorting in the database. This was not included in openwebwork#1585 because I didn't want to cause merge conflicts with openwebwork#1569. The file is also cleaned up a bit and the gateway versions listing and homework problem listing sections separated in a more logical and readable way. Those sections were perltidied.
sorting in the database. This was not included in openwebwork#1585 because I didn't want to cause merge conflicts with openwebwork#1569. The file is also cleaned up a bit and the gateway versions listing and homework problem listing sections separated in a more logical and readable way. Those sections were perltidied.
sorting in the database. This was not included in openwebwork#1585 because I didn't want to cause merge conflicts with openwebwork#1569. The file is also cleaned up a bit and the gateway versions listing and homework problem listing sections separated in a more logical and readable way. Those sections were perltidied.
sorting in the database. This was not included in openwebwork#1585 because I didn't want to cause merge conflicts with openwebwork#1569. The file is also cleaned up a bit and the gateway versions listing and homework problem listing sections separated in a more logical and readable way. Those sections were perltidied.
sorting in the database. This was not included in openwebwork#1585 because I didn't want to cause merge conflicts with openwebwork#1569. The file is also cleaned up a bit and the gateway versions listing and homework problem listing sections separated in a more logical and readable way. Those sections were perltidied.
sorting in the database. This was not included in openwebwork#1585 because I didn't want to cause merge conflicts with openwebwork#1569. The file is also cleaned up a bit and the gateway versions listing and homework problem listing sections separated in a more logical and readable way. Those sections were perltidied.
sorting in the database. This was not included in openwebwork#1585 because I didn't want to cause merge conflicts with openwebwork#1569. The file is also cleaned up a bit and the gateway versions listing and homework problem listing sections separated in a more logical and readable way. Those sections were perltidied.
sorting in the database. This was not included in openwebwork#1585 because I didn't want to cause merge conflicts with openwebwork#1569. The file is also cleaned up a bit and the gateway versions listing and homework problem listing sections separated in a more logical and readable way. Those sections were perltidied.
sorting in the database. This was not included in openwebwork#1585 because I didn't want to cause merge conflicts with openwebwork#1569. The file is also cleaned up a bit and the gateway versions listing and homework problem listing sections separated in a more logical and readable way. Those sections were perltidied.
sorting in the database. This was not included in openwebwork#1585 because I didn't want to cause merge conflicts with openwebwork#1569. The file is also cleaned up a bit and the gateway versions listing and homework problem listing sections separated in a more logical and readable way. Those sections were perltidied.
sorting in the database. This was not included in openwebwork#1585 because I didn't want to cause merge conflicts with openwebwork#1569. The file is also cleaned up a bit and the gateway versions listing and homework problem listing sections separated in a more logical and readable way. Those sections were perltidied.
sorting in the database. This was not included in openwebwork#1585 because I didn't want to cause merge conflicts with openwebwork#1569. The file is also cleaned up a bit and the gateway versions listing and homework problem listing sections separated in a more logical and readable way. Those sections were perltidied.
… sets. This was a regression introduced in openwebwork#1585. I missed a place where the result of a list...Where method was used and needed to be mapped to the actual field value. I double checked, and this is the only place this was forgotten. Thanks @taniwallach for pointing this out.
… sets. This was a regression introduced in openwebwork#1585. I missed a place where the result of a list...Where method was used and needed to be mapped to the actual field value. I double checked, and this is the only place this was forgotten. Thanks @taniwallach for pointing this out.
sorting in the database. This was not included in openwebwork#1585 because I didn't want to cause merge conflicts with openwebwork#1569. The file is also cleaned up a bit and the gateway versions listing and homework problem listing sections separated in a more logical and readable way. Those sections were perltidied.
Most of the DBFIXME's scattered throughout the code have been dealt with. In some cases this was accomplished by doing exactly what was said. In some cases better approaches were used to consolidate calls and cache data.
In other cases the DBFIXME's were just deleted. The primary case of this is those asking for the usage of database iterators. Those are really not correct. The amount of data contained in the database queries is generally not substantial enough to justify their usage. Furthermore, the correct usage of database iteration (not implemented in webwork) would accumulate data into chunks of a more significant size rather than handle each row separately.
WHEREclauses are used to obtain records, rather than listing id's and then filtering on those id's.ORDER BYclauses are used to do sorting in the database, rather than sorting in perl.This usage has been tested on a course that I have that has more than 40,000 users. Significant speed improvements are seen particularly on the pages that utilize the data for all users, like the classlist editor, statistics, and student progress pages.
Note that now the set level proctor users are not visible anywhere in the user interface. Previously they were hidden on the classlist editor page, but showed up many places where they should not have. There isn't anywhere that they should be shown.
Also note that several invalid
eflags on regex expressions have been removed in Grades.pm and SendMail.pm. There was a FIXME in Grades.pm stating that this flag is not needed for variable interpolation, and it isn't. I have seen also seen errors due to these flags being used.I recommend using the "Hide Whitespace" option to view this (if you haven't become accustomed to this already).
I also added a .perltidyrc file and ran perltidy on all of the files in the directory lib/WeBWorK/DB. There are no operational changes to those files, so just ignore them in reviewing this pull request. The pull request is currently in two commits. The first has all of the real changes, and the second the perltidy stuff. (Note that the .perltidyrc file is the same as the webwork3 file except I added the
-xcioption. We may want to add that to webwork3's file and the pg one also. That does a much better job of indentation with nested structures.)This is #1583 again. @pstaabp be more careful!