From 5287dff949c8be7423f1a710775dea6860d3c8b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Thu, 23 Jun 2016 13:51:37 +0200 Subject: [PATCH] Version 15.228.1 --- swad_changelog.h | 3 +- swad_global.c | 19 +++++------ swad_message.c | 17 ++++++---- swad_statistic.c | 9 ++--- swad_test.c | 9 ++--- swad_user.c | 87 +++++++++++++++++------------------------------- 6 files changed, 60 insertions(+), 84 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index 86d371c4..48ef68c1 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -129,13 +129,14 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 15.228 (2016-06-23)" +#define Log_PLATFORM_VERSION "SWAD 15.228.1 (2016-06-23)" #define CSS_FILE "swad15.226.css" #define JS_FILE "swad15.226.js" // Number of lines (includes comments but not blank lines) has been got with the following command: // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1 /* + Version 15.228.1 Jun 23, 2015 Code refactoring in lists of users. (202794 lines) Version 15.228 Jun 23, 2015 Code refactoring in lists of users. (202814 lines) Version 15.227.1 Jun 23, 2015 Code refactoring in getting/searching users. (202854 lines) Version 15.227: Jun 21, 2015 Query optimization in search of users. (202820 lines) diff --git a/swad_global.c b/swad_global.c index 1f1046f5..c2bdc1ff 100644 --- a/swad_global.c +++ b/swad_global.c @@ -81,6 +81,7 @@ void Gbl_InitializeGlobals (void) extern const char *The_ThemeId[The_NUM_THEMES]; extern const char *Ico_IconSetId[Ico_NUM_ICON_SETS]; extern const unsigned Txt_Current_CGI_SWAD_Language; + Rol_Role_t Role; Txt_Language_t Lan; Gbl.Layout.WritingHTMLStart = @@ -183,17 +184,13 @@ void Gbl_InitializeGlobals (void) Gbl.Action.UsesAJAX = false; Gbl.Action.Tab = TabUnk; - Gbl.Usrs.LstUsrs[Rol__GUEST_].Lst = NULL; - Gbl.Usrs.LstUsrs[Rol__GUEST_].NumUsrs = 0; - - Gbl.Usrs.LstUsrs[Rol_STUDENT].Lst = NULL; - Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs = 0; - - Gbl.Usrs.LstUsrs[Rol_TEACHER].Lst = NULL; - Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs = 0; - - Gbl.Usrs.LstUsrs[Rol_DEG_ADM].Lst = NULL; // Used to list of administrators of any scope, not only degree administrators - Gbl.Usrs.LstUsrs[Rol_DEG_ADM].NumUsrs = 0; + for (Role = (Rol_Role_t) 0; + Role < Rol_NUM_ROLES; + Role++) + { + Gbl.Usrs.LstUsrs[Role].Lst = NULL; + Gbl.Usrs.LstUsrs[Role].NumUsrs = 0; + } Gbl.ExamAnnouncements.NumExaAnns = 0; Gbl.ExamAnnouncements.Lst = NULL; diff --git a/swad_message.c b/swad_message.c index acf5fca3..8c006d19 100644 --- a/swad_message.c +++ b/swad_message.c @@ -232,7 +232,10 @@ void Msg_ListEMails (void) fprintf (Gbl.F.Out,"" ""); fprintf (Gbl.F.Out,Txt_X_students_who_have_accepted_and_who_have_e_mail, - NumAcceptedStdsWithEmail,((float) NumAcceptedStdsWithEmail / (float) Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs) * 100.0,Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs); + NumAcceptedStdsWithEmail, + ((float) NumAcceptedStdsWithEmail / + (float) Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs) * 100.0, + Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs); fprintf (Gbl.F.Out,"" ""); @@ -285,6 +288,7 @@ static void Msg_PutFormMsgUsrs (const char *Content) extern const char *Txt_MSG_To; extern const char *Txt_Send_message; char YN[1+1]; + unsigned NumTotalUsrs = 0; Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs = Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs = 0; @@ -330,15 +334,15 @@ static void Msg_PutFormMsgUsrs (const char *Content) /***** Get and order lists of users from this course *****/ Usr_GetListUsrs (Rol_TEACHER,Sco_SCOPE_CRS); Usr_GetListUsrs (Rol_STUDENT,Sco_SCOPE_CRS); + NumTotalUsrs = Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs + + Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs; - if (Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs || - Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs) + if (NumTotalUsrs) /***** Get lists of selected users *****/ Usr_GetListsSelectedUsrs (); } - if (Usr_GetIfShowBigList (Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs + - Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs)) + if (Usr_GetIfShowBigList (NumTotalUsrs)) { /***** Start frame *****/ Lay_StartRoundFrame (NULL, @@ -347,8 +351,7 @@ static void Msg_PutFormMsgUsrs (const char *Content) NULL); /***** Form to select type of list used for select several users *****/ - if (Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs || - Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs) + if (NumTotalUsrs) Usr_ShowFormsToSelectUsrListType (ActReqMsgUsr); /***** Form to show several potential recipients *****/ diff --git a/swad_statistic.c b/swad_statistic.c index ff9b2518..10498e08 100644 --- a/swad_statistic.c +++ b/swad_statistic.c @@ -405,6 +405,7 @@ void Sta_AskShowCrsHits (void) extern const char *Txt_No_teachers_or_students_found; static unsigned long RowsPerPage[] = {10,20,30,40,50,100,500,1000,5000,10000,50000,100000}; #define NUM_OPTIONS_ROWS_PER_PAGE (sizeof (RowsPerPage) / sizeof (RowsPerPage[0])) + unsigned NumTotalUsrs; Sta_ClicksGroupedBy_t ClicksGroupedBy; unsigned long i; @@ -419,12 +420,12 @@ void Sta_AskShowCrsHits (void) /***** Get and order the lists of users of this course *****/ Usr_GetListUsrs (Rol_TEACHER,Sco_SCOPE_CRS); Usr_GetListUsrs (Rol_STUDENT,Sco_SCOPE_CRS); + NumTotalUsrs = Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs + + Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs; - if (Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs || - Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs) + if (NumTotalUsrs) { - if (Usr_GetIfShowBigList (Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs + - Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs)) + if (Usr_GetIfShowBigList (NumTotalUsrs)) { /***** Get lists of selected users *****/ Usr_GetListsSelectedUsrs (); diff --git a/swad_test.c b/swad_test.c index 3c028713..195dbc7f 100644 --- a/swad_test.c +++ b/swad_test.c @@ -6811,6 +6811,7 @@ void Tst_SelUsrsToSeeUsrsExams (void) extern const char *Txt_Exams; extern const char *Txt_Users; extern const char *Txt_See_exams; + unsigned NumTotalUsrs; /***** Get and update type of list, number of columns in class photo @@ -6823,12 +6824,12 @@ void Tst_SelUsrsToSeeUsrsExams (void) /***** Get and order lists of users from this course *****/ Usr_GetListUsrs (Rol_TEACHER,Sco_SCOPE_CRS); Usr_GetListUsrs (Rol_STUDENT,Sco_SCOPE_CRS); + NumTotalUsrs = Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs + + Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs; - if (Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs || - Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs) + if (NumTotalUsrs) { - if (Usr_GetIfShowBigList (Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs + - Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs)) + if (Usr_GetIfShowBigList (NumTotalUsrs)) { /***** Start frame *****/ Lay_StartRoundFrame (NULL,Txt_Exams,NULL); diff --git a/swad_user.c b/swad_user.c index b4dd6537..326057db 100644 --- a/swad_user.c +++ b/swad_user.c @@ -3820,6 +3820,11 @@ void Usr_SearchListUsrs (Rol_Role_t Role,const char *UsrQuery) "UsrCod", UsrQuery); else // Students / Teachers + /* + To achieve maximum speed, it's important to do the things in this order: + 1) Search for user's name (UsrQuery) getting candidate users + 2) Filter the candidate users according to scope + */ switch (Gbl.Scope.Current) { case Sco_SCOPE_SYS: @@ -4824,19 +4829,8 @@ void Usr_PutExtraParamsUsrList (Act_Action_t NextAction) void Usr_ListUsersToSelect (Rol_Role_t Role) { /***** If there are no users, don't list anything *****/ - switch (Role) - { - case Rol_STUDENT: - if (!Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs) - return; - break; - case Rol_TEACHER: - if (!Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs) - return; - break; - default: - return; - } + if (!Gbl.Usrs.LstUsrs[Role].NumUsrs) + return; /***** Put a row to select all users *****/ Usr_PutCheckboxToSelectAllTheUsers (Role); @@ -5539,38 +5533,17 @@ void Usr_ListUsrsForSelection (Rol_Role_t Role) Usr_UsrDataConstructor (&UsrDat); /***** List users' data *****/ - switch (Role) + for (NumUsr = 0, Gbl.RowEvenOdd = 0; + NumUsr < Gbl.Usrs.LstUsrs[Role].NumUsrs; ) { - case Rol_STUDENT: - for (NumUsr = 0, Gbl.RowEvenOdd = 0; - NumUsr < Gbl.Usrs.LstUsrs[Rol_STUDENT].NumUsrs; ) - { - UsrDat.UsrCod = Gbl.Usrs.LstUsrs[Rol_STUDENT].Lst[NumUsr].UsrCod; - if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // If user's data exist... - { - UsrDat.Accepted = Gbl.Usrs.LstUsrs[Rol_STUDENT].Lst[NumUsr].Accepted; - Usr_WriteRowUsrMainData (++NumUsr,&UsrDat,true); + UsrDat.UsrCod = Gbl.Usrs.LstUsrs[Role].Lst[NumUsr].UsrCod; + if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // If user's data exist... + { + UsrDat.Accepted = Gbl.Usrs.LstUsrs[Role].Lst[NumUsr].Accepted; + Usr_WriteRowUsrMainData (++NumUsr,&UsrDat,true); - Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd; - } - } - break; - case Rol_TEACHER: - for (NumUsr = 0, Gbl.RowEvenOdd = 0; - NumUsr < Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs; ) - { - UsrDat.UsrCod = Gbl.Usrs.LstUsrs[Rol_TEACHER].Lst[NumUsr].UsrCod; - if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) // If user's data exist... - { - UsrDat.Accepted = Gbl.Usrs.LstUsrs[Rol_TEACHER].Lst[NumUsr].Accepted; - Usr_WriteRowUsrMainData (++NumUsr,&UsrDat,true); - - Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd; - } - } - break; - default: - break; + Gbl.RowEvenOdd = 1 - Gbl.RowEvenOdd; + } } /***** Free memory used for user's data *****/ @@ -6353,7 +6326,7 @@ void Usr_SeeGuests (void) Lay_WriteHeaderClassPhoto (false,true, (Gbl.Scope.Current == Sco_SCOPE_CTR || Gbl.Scope.Current == Sco_SCOPE_INS) ? Gbl.CurrentIns.Ins.InsCod : - -1L, + -1L, -1L, -1L); @@ -6509,12 +6482,12 @@ void Usr_SeeStudents (void) Gbl.Scope.Current == Sco_SCOPE_DEG || Gbl.Scope.Current == Sco_SCOPE_CTR || Gbl.Scope.Current == Sco_SCOPE_INS) ? Gbl.CurrentIns.Ins.InsCod : - -1L, + -1L, (Gbl.Scope.Current == Sco_SCOPE_CRS || Gbl.Scope.Current == Sco_SCOPE_DEG) ? Gbl.CurrentDeg.Deg.DegCod : - -1L, - Gbl.Scope.Current == Sco_SCOPE_CRS ? Gbl.CurrentCrs.Crs.CrsCod : - -1L); + -1L, + Gbl.Scope.Current == Sco_SCOPE_CRS ? Gbl.CurrentCrs.Crs.CrsCod : + -1L); /* Start table */ fprintf (Gbl.F.Out,""); @@ -6623,7 +6596,7 @@ void Usr_SeeTeachers (void) /***** Start frame *****/ Lay_StartRoundFrame (NULL,Txt_ROLES_PLURAL_Abc[Rol_TEACHER][Usr_SEX_UNKNOWN], (Gbl.Usrs.Me.ListType == Usr_CLASS_PHOTO) ? (Gbl.Usrs.LstUsrs[Rol_TEACHER].NumUsrs ? Usr_PutIconToPrintTchs : - NULL) : + NULL) : ((Gbl.Usrs.Me.LoggedRole >= Rol_DEG_ADM) ? Usr_PutIconToShowTchsAllData : NULL)); @@ -6655,12 +6628,12 @@ void Usr_SeeTeachers (void) Gbl.Scope.Current == Sco_SCOPE_DEG || Gbl.Scope.Current == Sco_SCOPE_CTR || Gbl.Scope.Current == Sco_SCOPE_INS) ? Gbl.CurrentIns.Ins.InsCod : - -1L, + -1L, (Gbl.Scope.Current == Sco_SCOPE_CRS || Gbl.Scope.Current == Sco_SCOPE_DEG) ? Gbl.CurrentDeg.Deg.DegCod : - -1L, - Gbl.Scope.Current == Sco_SCOPE_CRS ? Gbl.CurrentCrs.Crs.CrsCod : - -1L); + -1L, + Gbl.Scope.Current == Sco_SCOPE_CRS ? Gbl.CurrentCrs.Crs.CrsCod : + -1L); /* Start table */ fprintf (Gbl.F.Out,"
"); @@ -6864,12 +6837,12 @@ void Usr_SeeStdClassPhotoPrn (void) Gbl.Scope.Current == Sco_SCOPE_DEG || Gbl.Scope.Current == Sco_SCOPE_CTR || Gbl.Scope.Current == Sco_SCOPE_INS) ? Gbl.CurrentIns.Ins.InsCod : - -1L, + -1L, (Gbl.Scope.Current == Sco_SCOPE_CRS || Gbl.Scope.Current == Sco_SCOPE_DEG) ? Gbl.CurrentDeg.Deg.DegCod : - -1L, - Gbl.Scope.Current == Sco_SCOPE_CRS ? Gbl.CurrentCrs.Crs.CrsCod : - -1L); + -1L, + Gbl.Scope.Current == Sco_SCOPE_CRS ? Gbl.CurrentCrs.Crs.CrsCod : + -1L); fprintf (Gbl.F.Out,"
"); Usr_DrawClassPhoto (Usr_CLASS_PHOTO_PRN,Rol_STUDENT); fprintf (Gbl.F.Out,"
");