From 9eb7a17d302722af0c615d5a40a687c43b0c6967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Mon, 18 Feb 2019 09:40:46 +0100 Subject: [PATCH] Version 18.48.1 --- swad_action.c | 13 ++-- swad_changelog.h | 3 +- swad_group.c | 151 ++++++++++++++++++----------------------------- swad_group.h | 3 +- 4 files changed, 67 insertions(+), 103 deletions(-) diff --git a/swad_action.c b/swad_action.c index 1d6d7eb36..ee27475c2 100644 --- a/swad_action.c +++ b/swad_action.c @@ -5329,13 +5329,12 @@ void Act_AdjustCurrentAction (void) default: /* If there are some group types with groups in wich I must register, the the only action possible is show a form to register in groups */ - if (Gbl.Action.Act == ActLogIn) // Only when login... - if (Grp_ThereAreGrpTypesIMustRegister ()) // ...because this query is slow - { - Gbl.Action.Act = ActReqSelGrp; - Tab_SetCurrentTab (); - return; - } + if (Grp_GetIfAnyMandatoryGrpTypIsAvailable ()) // This query may be slow + { + Gbl.Action.Act = ActReqSelGrp; + Tab_SetCurrentTab (); + return; + } /* If I have no photo, and current action is not available for unknown users, then update number of clicks without photo */ diff --git a/swad_changelog.h b/swad_changelog.h index e62abf416..f1576ed23 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -402,10 +402,11 @@ En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 18.48 (2019-02-18)" +#define Log_PLATFORM_VERSION "SWAD 18.48.1 (2019-02-18)" #define CSS_FILE "swad18.41.1.css" #define JS_FILE "swad18.32.1.js" /* + Version 18.48.1: Feb 18, 2019 Optimization on query about available mandatory group types. (237548 lines) Version 18.48: Feb 18, 2019 Fixed bugs in actions related to account. Fixed bug related with groups. (237589 lines) 1 change necessary in database: diff --git a/swad_group.c b/swad_group.c index a107aaa5c..1bc1eb518 100644 --- a/swad_group.c +++ b/swad_group.c @@ -131,7 +131,7 @@ static bool Grp_GetMultipleEnrolmentOfAGroupType (long GrpTypCod); static long Grp_GetTypeOfGroupOfAGroup (long GrpCod); static unsigned long Grp_CountNumUsrsInNoGrpsOfType (Rol_Role_t Role,long GrpTypCod); static long Grp_GetFirstCodGrpIBelongTo (long GrpTypCod); -static bool Grp_GetIfGrpIsAvailable (long GrpTypCod); +static bool Grp_GetIfGrpTypIsAvailable (long GrpTypCod); static void Grp_GetLstCodGrpsUsrBelongs (long CrsCod,long GrpTypCod,long UsrCod, struct ListCodGrps *LstGrps); static bool Grp_CheckIfGrpIsInList (long GrpCod,struct ListCodGrps *LstGrps); @@ -1899,7 +1899,7 @@ static void Grp_ShowWarningToStdsToChangeGrps (void) GrpTyp = &Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp]; if (GrpTyp->NumGrps) // If there are groups of this type if (Grp_GetFirstCodGrpIBelongTo (GrpTyp->GrpTypCod) < 0) // If I don't belong to any group - if (Grp_GetIfGrpIsAvailable (GrpTyp->GrpTypCod)) // If there is any group of this type available + if (Grp_GetIfGrpTypIsAvailable (GrpTyp->GrpTypCod)) // If there is any group of this type available { if (GrpTyp->MandatoryEnrolment) Ale_ShowAlert (Ale_WARNING,GrpTyp->MultipleEnrolment ? Txt_You_have_to_register_compulsorily_at_least_in_one_group_of_type_X : @@ -3360,10 +3360,11 @@ static long Grp_GetFirstCodGrpIBelongTo (long GrpTypCod) /***** Get a group which I belong to from database *****/ NumRows = DB_QuerySELECT (&mysql_res,"can not check if you belong to a group", - "SELECT crs_grp.GrpCod FROM crs_grp,crs_grp_usr" + "SELECT crs_grp.GrpCod" + " FROM crs_grp,crs_grp_usr" " WHERE crs_grp.GrpTypCod=%ld" " AND crs_grp.GrpCod=crs_grp_usr.GrpCod" - " AND crs_grp_usr.UsrCod=%ld", + " AND crs_grp_usr.UsrCod=%ld", // I belong GrpTypCod,Gbl.Usrs.Me.UsrDat.UsrCod); /***** Get the group *****/ @@ -3495,109 +3496,68 @@ bool Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (const struct UsrData *UsrDat) } /*****************************************************************************/ -/****** Are there any group types with groups in wich I must register? *******/ +/**** Query if any mandatory group in this course is open and has vacants ****/ /*****************************************************************************/ -bool Grp_ThereAreGrpTypesIMustRegister (void) +bool Grp_GetIfAnyMandatoryGrpTypIsAvailable (void) { - unsigned NumGrpTypesEmptyIMustRegister; - unsigned NumGrpTypesNotEmptyIMustRegister; + unsigned NumGrpTypes; - /***** - Number of group types: - - with mandatory registration - - with groups: - - open - - not full - - empty - *****/ - NumGrpTypesEmptyIMustRegister = - (unsigned) DB_QueryCOUNT ("can not get group types I must register", - // Mandatory group types open, which admit students - " SELECT COUNT(DISTINCT crs_grp_types.GrpTypCod)" - " FROM crs_grp_types,crs_grp" - " WHERE crs_grp_types.CrsCod=%ld" - " AND crs_grp_types.Mandatory='Y'" // Mandatory registration - " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" - " AND crs_grp.Open='Y'" // Open - " AND crs_grp.MaxStudents>0" // Admits students - // Empty, without students - " AND crs_grp_types.GrpTypCod NOT IN" - // Mandatory group types open, which admit students, with students - " (SELECT DISTINCT crs_grp_types.GrpTypCod" - " FROM crs_grp_types,crs_grp,crs_grp_usr,crs_usr" - " WHERE crs_grp_types.CrsCod=%ld" - " AND crs_grp_types.Mandatory='Y'" // Mandatory registration - " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" - " AND crs_grp.Open='Y'" // Open - " AND crs_grp.MaxStudents>0" // Admits students - " AND crs_grp_types.CrsCod=crs_usr.CrsCod" - " AND crs_grp.GrpCod=crs_grp_usr.GrpCod" - " AND crs_grp_usr.UsrCod=crs_usr.UsrCod" - " AND crs_usr.Role=%u)", - Gbl.CurrentCrs.Crs.CrsCod, - Gbl.CurrentCrs.Crs.CrsCod, - Gbl.CurrentCrs.Crs.CrsCod, - (unsigned) Rol_STD); - if (NumGrpTypesEmptyIMustRegister) - return true; + /***** Get the number of types of group in this course + with one or more open groups with vacants, from database *****/ + NumGrpTypes = + (unsigned) DB_QueryCOUNT ("can not check if there has available mandatory group types", + "SELECT COUNT(GrpTypCod) FROM " + "(" - /***** - Number of group types: - - with mandatory registration - - with groups: - - open - - not full - - not empty - - to which I don't belong - *****/ - NumGrpTypesNotEmptyIMustRegister = - (unsigned) DB_QueryCOUNT ("can not get group types I must register", - // Number of group types - "SELECT COUNT(DISTINCT GrpTypCod) FROM" - - // Mandatory group types open, which admit students, not full - " (SELECT crs_grp_types.GrpTypCod AS GrpTypCod," + // Available groups with students + "SELECT crs_grp_types.GrpTypCod AS GrpTypCod," "COUNT(*) AS NumStudents," "crs_grp.MaxStudents as MaxStudents" " FROM crs_grp_types,crs_grp,crs_grp_usr,crs_usr" - " WHERE crs_grp_types.CrsCod=%ld" - " AND crs_grp_types.Mandatory='Y'" // Mandatory registration + " WHERE crs_grp_types.CrsCod=%ld" // In this course " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" - " AND crs_grp.Open='Y'" // Open - " AND crs_grp.MaxStudents>0" // Admits students + " AND crs_grp.Open='Y'" // Open + " AND crs_grp.MaxStudents > 0" // Admits students " AND crs_grp_types.CrsCod=crs_usr.CrsCod" " AND crs_grp.GrpCod=crs_grp_usr.GrpCod" " AND crs_grp_usr.UsrCod=crs_usr.UsrCod" - " AND crs_usr.Role=%u" + " AND crs_usr.Role=%u" // With some student " GROUP BY crs_grp.GrpCod" - " HAVING NumStudents0" // Admits students - " AND crs_grp.GrpCod=crs_grp_usr.GrpCod" - " AND crs_grp_usr.UsrCod=%ld)", + " AND crs_grp.Open='Y'" // Open + " AND crs_grp.MaxStudents > 0" // Admits students + " AND crs_grp.GrpCod NOT IN" // Only if empty + " (SELECT crs_grp_usr.GrpCod" + " FROM crs_usr,crs_grp_usr" + " WHERE crs_usr.CrsCod=%ld" + " AND crs_usr.Role=%u" + " AND crs_usr.UsrCod=crs_grp_usr.UsrCod)" + ") AS available_grp_types", + + Gbl.CurrentCrs.Crs.CrsCod,(unsigned) Rol_STD, Gbl.CurrentCrs.Crs.CrsCod, - (unsigned) Rol_STD, - Gbl.CurrentCrs.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); - return (NumGrpTypesNotEmptyIMustRegister > 0); + Gbl.CurrentCrs.Crs.CrsCod,(unsigned) Rol_STD); + + return (NumGrpTypes != 0); } /*****************************************************************************/ /********** Query if any group of a type is open and has vacants *************/ /*****************************************************************************/ -static bool Grp_GetIfGrpIsAvailable (long GrpTypCod) +static bool Grp_GetIfGrpTypIsAvailable (long GrpTypCod) { unsigned NumGrpTypes; @@ -3607,33 +3567,35 @@ static bool Grp_GetIfGrpIsAvailable (long GrpTypCod) (unsigned) DB_QueryCOUNT ("can not check if a type of group has available groups", "SELECT COUNT(GrpTypCod) FROM " "(" - // Groups with students + + // Available groups with students "SELECT crs_grp_types.GrpTypCod AS GrpTypCod," "COUNT(*) AS NumStudents," "crs_grp.MaxStudents as MaxStudents" " FROM crs_grp_types,crs_grp,crs_grp_usr,crs_usr" - " WHERE crs_grp_types.GrpTypCod=%ld" + " WHERE crs_grp_types.GrpTypCod=%ld" // Of this type " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" - " AND crs_grp.Open='Y'" + " AND crs_grp.Open='Y'" // Open + " AND crs_grp.MaxStudents > 0" // Admits students " AND crs_grp_types.CrsCod=crs_usr.CrsCod" " AND crs_grp.GrpCod=crs_grp_usr.GrpCod" " AND crs_grp_usr.UsrCod=crs_usr.UsrCod" - " AND crs_usr.Role=%u" + " AND crs_usr.Role=%u" // With some student " GROUP BY crs_grp.GrpCod" - " HAVING NumStudents 0" - " AND crs_grp.GrpCod NOT IN" + " AND crs_grp.Open='Y'" // Open + " AND crs_grp.MaxStudents > 0" // Admits students + " AND crs_grp.GrpCod NOT IN" // Only if empty " (SELECT crs_grp_usr.GrpCod" " FROM crs_grp_types,crs_usr,crs_grp_usr" " WHERE crs_grp_types.GrpTypCod=%ld" @@ -3642,6 +3604,7 @@ static bool Grp_GetIfGrpIsAvailable (long GrpTypCod) " AND crs_usr.UsrCod=crs_grp_usr.UsrCod)" ") AS available_grp_types", + GrpTypCod,(unsigned) Rol_STD, GrpTypCod, GrpTypCod,(unsigned) Rol_STD); diff --git a/swad_group.h b/swad_group.h index f1acc7947..d33638055 100644 --- a/swad_group.h +++ b/swad_group.h @@ -186,7 +186,8 @@ bool Grp_GetIfIBelongToGrp (long GrpCod); void Grp_FlushCacheUsrSharesAnyOfMyGrpsInCurrentCrs (void); bool Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (const struct UsrData *UsrDat); -bool Grp_ThereAreGrpTypesIMustRegister (void); +bool Grp_GetIfAnyMandatoryGrpTypIsAvailable (void); + void Grp_GetLstCodGrpsWithFileZonesIBelong (struct ListCodGrps *LstGrps); void Grp_GetNamesGrpsStdBelongsTo (long GrpTypCod,long UsrCod,char *GrpNames); void Grp_RecFormNewGrpTyp (void);