diff --git a/swad_account.c b/swad_account.c index 9a3675f6a..f4873a73a 100644 --- a/swad_account.c +++ b/swad_account.c @@ -1051,7 +1051,7 @@ void Acc_CompletelyEliminateAccount (struct UsrData *UsrDat, /***** Remove user from the tables of courses and users *****/ DB_QueryDELETE ("can not remove a user from all courses", - "DELETE FROM crs_usr_last WHERE UsrCod=%ld", + "DELETE FROM usr_crs_last WHERE UsrCod=%ld", UsrDat->UsrCod); DB_QueryDELETE ("can not remove a user from all courses", "DELETE FROM crs_usr WHERE UsrCod=%ld", diff --git a/swad_changelog.h b/swad_changelog.h index 0439a1b4a..99ab23bf0 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -544,10 +544,18 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 19.207 (2020-04-29)" +#define Log_PLATFORM_VERSION "SWAD 19.207.1 (2020-04-29)" #define CSS_FILE "swad19.193.1.css" #define JS_FILE "swad19.193.1.js" /* + Version 19.207.1: Apr 30, 2020 Optimization in table of last prefs on user-course. (300323 lines) + 5 changes necessary in database: +ALTER TABLE crs_usr CHANGE COLUMN CrsCod CrsCod INT NOT NULL; +ALTER TABLE crs_usr_last CHANGE COLUMN CrsCod CrsCod INT NOT NULL AFTER UsrCod; +ALTER TABLE crs_usr_last DROP INDEX CrsCod; +OPTIMIZE TABLE crs_usr; +OPTIMIZE TABLE crs_usr_last; + Version 19.207: Apr 30, 2020 Table with inscriptions of users in courses is splitted into two tables for speed. (300323 lines) 8 changes necessary in database: RENAME TABLE crs_usr_old TO crs_usr_old_backup_delete_me; diff --git a/swad_database.c b/swad_database.c index 231154480..5c1e6468b 100644 --- a/swad_database.c +++ b/swad_database.c @@ -847,27 +847,18 @@ mysql> DESCRIBE crs_records; /***** Table crs_usr *****/ /* mysql> DESCRIBE crs_usr; -+----------------+---------------------------+------+-----+------------+-------+ -| Field | Type | Null | Key | Default | Extra | -+----------------+---------------------------+------+-----+------------+-------+ -| CrsCod | int(11) | NO | PRI | -1 | | -| UsrCod | int(11) | NO | PRI | NULL | | -| Role | tinyint(4) | NO | PRI | 0 | | -| Accepted | enum('N','Y') | NO | | N | | -| LastDowGrpCod | int(11) | NO | | -1 | | -| LastComGrpCod | int(11) | NO | | -1 | | -| LastAssGrpCod | int(11) | NO | | -1 | | -| NumAccTst | int(11) | NO | | 0 | | -| LastAccTst | datetime | NO | | NULL | | -| NumQstsLastTst | int(11) | NO | | 0 | | -| UsrListType | enum('classphoto','list') | NO | | classphoto | | -| ColsClassPhoto | tinyint(4) | NO | | NULL | | -| ListWithPhotos | enum('N','Y') | NO | | Y | | -+----------------+---------------------------+------+-----+------------+-------+ -13 rows in set (0.00 sec) ++----------+---------------+------+-----+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++----------+---------------+------+-----+---------+-------+ +| CrsCod | int(11) | NO | PRI | NULL | | +| UsrCod | int(11) | NO | PRI | NULL | | +| Role | tinyint(4) | NO | MUL | 0 | | +| Accepted | enum('N','Y') | NO | | N | | ++----------+---------------+------+-----+---------+-------+ +4 rows in set (0.00 sec) */ DB_CreateTable ("CREATE TABLE IF NOT EXISTS crs_usr (" - "CrsCod INT NOT NULL DEFAULT -1," + "CrsCod INT NOT NULL," "UsrCod INT NOT NULL," "Role TINYINT NOT NULL DEFAULT 0," "Accepted ENUM('N','Y') NOT NULL DEFAULT 'N'," @@ -886,10 +877,8 @@ mysql> DESCRIBE crs_usr_last; +----------------+---------------------------+------+-----+------------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------+---------------------------+------+-----+------------+-------+ -| CrsCod | int(11) | NO | PRI | -1 | | | UsrCod | int(11) | NO | PRI | NULL | | -| Role | tinyint(4) | NO | PRI | 0 | | -| Accepted | enum('N','Y') | NO | | N | | +| CrsCod | int(11) | NO | PRI | NULL | | | LastDowGrpCod | int(11) | NO | | -1 | | | LastComGrpCod | int(11) | NO | | -1 | | | LastAssGrpCod | int(11) | NO | | -1 | | @@ -900,11 +889,11 @@ mysql> DESCRIBE crs_usr_last; | ColsClassPhoto | tinyint(4) | NO | | NULL | | | ListWithPhotos | enum('N','Y') | NO | | Y | | +----------------+---------------------------+------+-----+------------+-------+ -13 rows in set (0.00 sec) +11 rows in set (0.00 sec) */ DB_CreateTable ("CREATE TABLE IF NOT EXISTS crs_usr_last (" - "CrsCod INT NOT NULL DEFAULT -1," "UsrCod INT NOT NULL," + "CrsCod INT NOT NULL," "LastDowGrpCod INT NOT NULL DEFAULT -1," "LastComGrpCod INT NOT NULL DEFAULT -1," "LastAssGrpCod INT NOT NULL DEFAULT -1," @@ -914,7 +903,6 @@ mysql> DESCRIBE crs_usr_last; "UsrListType ENUM('classphoto','list') NOT NULL DEFAULT 'classphoto'," "ColsClassPhoto TINYINT NOT NULL," "ListWithPhotos ENUM('N','Y') NOT NULL DEFAULT 'Y'," - "UNIQUE INDEX(CrsCod,UsrCod)," "UNIQUE INDEX(UsrCod,CrsCod))"); /***** Table crs_usr_requests *****/ diff --git a/swad_enrolment.c b/swad_enrolment.c index ae3b29f83..51d3d4fc1 100644 --- a/swad_enrolment.c +++ b/swad_enrolment.c @@ -300,7 +300,7 @@ void Enr_RegisterUsrInCurrentCrs (struct UsrData *UsrDat,Rol_Role_t NewRole, /***** Register last prefs in current course in database *****/ DB_QueryINSERT ("can not register user in course", "INSERT INTO crs_usr_last" - " (CrsCod,UsrCod," + " (UsrCod,CrsCod," "LastDowGrpCod,LastComGrpCod,LastAssGrpCod," "NumAccTst,LastAccTst,NumQstsLastTst," "UsrListType,ColsClassPhoto,ListWithPhotos)" @@ -309,7 +309,7 @@ void Enr_RegisterUsrInCurrentCrs (struct UsrData *UsrDat,Rol_Role_t NewRole, "-1,-1,-1," "0,FROM_UNIXTIME(%ld),0," "'%s',%u,'%c')", - Gbl.Hierarchy.Crs.CrsCod,UsrDat->UsrCod, + UsrDat->UsrCod,Gbl.Hierarchy.Crs.CrsCod, (long) (time_t) 0, // The user never accessed to tests in this course Usr_StringsUsrListTypeInDB[Usr_SHOW_USRS_TYPE_DEFAULT], Usr_CLASS_PHOTO_COLS_DEF, @@ -4137,8 +4137,8 @@ static void Enr_EffectivelyRemUsrFromCrs (struct UsrData *UsrDat, /***** Remove user from the tables of courses-users *****/ DB_QueryDELETE ("can not remove a user from a course", "DELETE FROM crs_usr_last" - " WHERE CrsCod=%ld AND UsrCod=%ld", - Crs->CrsCod,UsrDat->UsrCod); + " WHERE UsrCod=%ld AND CrsCod=%ld", + UsrDat->UsrCod,Crs->CrsCod); DB_QueryDELETE ("can not remove a user from a course", "DELETE FROM crs_usr" " WHERE CrsCod=%ld AND UsrCod=%ld", diff --git a/swad_file_browser.c b/swad_file_browser.c index f80db7e4d..d5486a4ef 100644 --- a/swad_file_browser.c +++ b/swad_file_browser.c @@ -3922,9 +3922,10 @@ static void Brw_UpdateGrpLastAccZone (const char *FieldNameDB,long GrpCod) /***** Update the group of my last access to a common zone *****/ DB_QueryUPDATE ("can not update the group of the last access to a file browser", "UPDATE crs_usr_last SET %s=%ld" - " WHERE CrsCod=%ld AND UsrCod=%ld", + " WHERE UsrCod=%ld AND CrsCod=%ld", FieldNameDB,GrpCod, - Gbl.Hierarchy.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod); + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Hierarchy.Crs.CrsCod); } /*****************************************************************************/ @@ -5250,10 +5251,10 @@ static long Brw_GetGrpLastAccZone (const char *FieldNameDB) " of your last access" " to a file browser", "SELECT %s FROM crs_usr_last" - " WHERE CrsCod=%ld AND UsrCod=%ld", + " WHERE UsrCod=%ld AND CrsCod=%ld", FieldNameDB, - Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Hierarchy.Crs.CrsCod); if (NumRows == 0) // May be an administrator not belonging to this course GrpCod = -1L; diff --git a/swad_test.c b/swad_test.c index 0c91f0267..6aa9fb0f0 100644 --- a/swad_test.c +++ b/swad_test.c @@ -705,10 +705,10 @@ static bool Tst_CheckIfNextTstAllowed (void) "UNIX_TIMESTAMP()," // row[0] "UNIX_TIMESTAMP(LastAccTst+INTERVAL (NumQstsLastTst*%lu) SECOND)" // row[1] " FROM crs_usr_last" - " WHERE CrsCod=%ld AND UsrCod=%ld", + " WHERE UsrCod=%ld AND CrsCod=%ld", TstCfg_GetConfigMinTimeNxtTstPerQst (), TstCfg_GetConfigMinTimeNxtTstPerQst (), - Gbl.Hierarchy.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod) == 1) + Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.Hierarchy.Crs.CrsCod) == 1) { /* Get seconds from now to next access to test */ row = mysql_fetch_row (mysql_res); @@ -758,9 +758,9 @@ static unsigned Tst_GetNumExamsGeneratedByMe (void) NumRows = DB_QuerySELECT (&mysql_res,"can not get number of test exams generated", "SELECT NumAccTst" // row[0] " FROM crs_usr_last" - " WHERE CrsCod=%ld AND UsrCod=%ld", - Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); + " WHERE UsrCod=%ld AND CrsCod=%ld", + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Hierarchy.Crs.CrsCod); if (NumRows == 0) NumExamsGeneratedByMe = 0; @@ -1170,8 +1170,9 @@ static void Tst_IncreaseMyNumAccessTst (void) /***** Update my number of accesses to test in this course *****/ DB_QueryUPDATE ("can not update the number of accesses to test", "UPDATE crs_usr_last SET NumAccTst=NumAccTst+1" - " WHERE CrsCod=%ld AND UsrCod=%ld", - Gbl.Hierarchy.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod); + " WHERE UsrCod=%ld AND CrsCod=%ld", + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Hierarchy.Crs.CrsCod); } /*****************************************************************************/ @@ -1183,10 +1184,10 @@ static void Tst_UpdateLastAccTst (unsigned NumQsts) /***** Update date-time and number of questions of this test *****/ DB_QueryUPDATE ("can not update time and number of questions of this test", "UPDATE crs_usr_last SET LastAccTst=NOW(),NumQstsLastTst=%u" - " WHERE CrsCod=%ld AND UsrCod=%ld", + " WHERE UsrCod=%ld AND CrsCod=%ld", NumQsts, - Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Hierarchy.Crs.CrsCod); } /*****************************************************************************/ diff --git a/swad_user.c b/swad_user.c index 3a0b6f769..ac414a811 100644 --- a/swad_user.c +++ b/swad_user.c @@ -7599,9 +7599,9 @@ static void Usr_GetMyUsrListTypeFromDB (void) /***** Get type of listing of users from database *****/ NumRows = DB_QuerySELECT (&mysql_res,"can not get type of listing of users", "SELECT UsrListType FROM crs_usr_last" - " WHERE CrsCod=%ld AND UsrCod=%ld", - Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); + " WHERE UsrCod=%ld AND CrsCod=%ld", + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Hierarchy.Crs.CrsCod); if (NumRows == 1) // Should be one only row { /* Get type of users' listing used to select some of them */ @@ -7638,9 +7638,10 @@ static void Usr_UpdateMyUsrListTypeInDB (void) /***** Update type of users listing *****/ DB_QueryUPDATE ("can not update type of listing", "UPDATE crs_usr_last SET UsrListType='%s'" - " WHERE CrsCod=%ld AND UsrCod=%ld", + " WHERE UsrCod=%ld AND CrsCod=%ld", Usr_StringsUsrListTypeInDB[Gbl.Usrs.Me.ListType], - Gbl.Hierarchy.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod); + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Hierarchy.Crs.CrsCod); } /*****************************************************************************/ @@ -7703,9 +7704,9 @@ static void Usr_GetMyColsClassPhotoFromDB (void) NumRows = DB_QuerySELECT (&mysql_res,"can not get number of columns" " in class photo", "SELECT ColsClassPhoto FROM crs_usr_last" - " WHERE CrsCod=%ld AND UsrCod=%ld", - Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); + " WHERE UsrCod=%ld AND CrsCod=%ld", + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Hierarchy.Crs.CrsCod); if (NumRows == 1) // Should be one only row { /* Get number of columns in class photo */ @@ -7737,9 +7738,10 @@ static void Usr_UpdateMyColsClassPhotoInDB (void) /***** Update number of colums in class photo for current course *****/ DB_QueryUPDATE ("can not update number of columns in class photo", "UPDATE crs_usr_last SET ColsClassPhoto=%u" - " WHERE CrsCod=%ld AND UsrCod=%ld", + " WHERE UsrCod=%ld AND CrsCod=%ld", Gbl.Usrs.ClassPhoto.Cols, - Gbl.Hierarchy.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod); + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Hierarchy.Crs.CrsCod); } /*****************************************************************************/ @@ -7807,9 +7809,9 @@ void Usr_GetMyPrefAboutListWithPhotosFromDB (void) NumRows = DB_QuerySELECT (&mysql_res,"can not check if listing of users" " must show photos", "SELECT ListWithPhotos FROM crs_usr_last" - " WHERE CrsCod=%ld AND UsrCod=%ld", - Gbl.Hierarchy.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); + " WHERE UsrCod=%ld AND CrsCod=%ld", + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Hierarchy.Crs.CrsCod); if (NumRows == 1) // Should be one only row { /* Get number of columns in class photo */ @@ -7838,10 +7840,11 @@ static void Usr_UpdateMyPrefAboutListWithPhotosPhotoInDB (void) /***** Update number of colums in class photo for current course *****/ DB_QueryUPDATE ("can not update your preference about photos in listing", "UPDATE crs_usr_last SET ListWithPhotos='%c'" - " WHERE CrsCod=%ld AND UsrCod=%ld", + " WHERE UsrCod=%ld AND CrsCod=%ld", Gbl.Usrs.Listing.WithPhotos ? 'Y' : 'N', - Gbl.Hierarchy.Crs.CrsCod,Gbl.Usrs.Me.UsrDat.UsrCod); + Gbl.Usrs.Me.UsrDat.UsrCod, + Gbl.Hierarchy.Crs.CrsCod); } /*****************************************************************************/