From e747318bbf88fccc05a5f7172f08f29aa42d2cff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Sun, 5 Jan 2020 12:52:03 +0100 Subject: [PATCH] Version19.112.8 --- swad_API.c | 4 +-- swad_centre.c | 17 +++++------ swad_changelog.h | 5 ++-- swad_chat.c | 4 +-- swad_course.c | 36 ++++++++++++++++------- swad_course.h | 1 + swad_course_config.c | 4 +-- swad_degree.c | 68 +++++++++++++++++++++----------------------- swad_degree.h | 11 ++----- swad_enrolment.c | 2 +- swad_exam.c | 2 +- swad_file_browser.c | 14 ++++----- swad_forum.c | 4 +-- swad_global.c | 1 + swad_global.h | 5 ++++ swad_hierarchy.c | 7 ++--- swad_layout.c | 2 +- swad_notification.c | 4 +-- swad_photo.c | 6 ++-- swad_report.c | 2 +- swad_statistic.c | 2 +- swad_timeline.c | 2 +- 22 files changed, 108 insertions(+), 95 deletions(-) diff --git a/swad_API.c b/swad_API.c index 9868b9c40..d628d52a4 100644 --- a/swad_API.c +++ b/swad_API.c @@ -1043,7 +1043,7 @@ int swad__loginBySessionKey (struct soap *soap, /***** Get degree (row[1]) *****/ Gbl.Hierarchy.Deg.DegCod = Str_ConvertStrCodToLongCod (row[1]); - Deg_GetDataOfDegreeByCod (&Gbl.Hierarchy.Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Gbl.Hierarchy.Deg); loginBySessionKeyOut->degreeCode = (int) Gbl.Hierarchy.Deg.DegCod; Str_Copy (loginBySessionKeyOut->degreeName,Gbl.Hierarchy.Deg.FullName, Hie_MAX_BYTES_FULL_NAME); @@ -3070,7 +3070,7 @@ int swad__getNotifications (struct soap *soap, /* Get degree (row[6]) */ Deg.DegCod = Str_ConvertStrCodToLongCod (row[6]); - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Deg); /* Get message/post/... code (row[8]) */ Cod = Str_ConvertStrCodToLongCod (row[8]); diff --git a/swad_centre.c b/swad_centre.c index 64ac8e4c4..75506c20c 100644 --- a/swad_centre.c +++ b/swad_centre.c @@ -606,15 +606,15 @@ bool Ctr_GetDataOfCentreByCod (struct Centre *Ctr) bool CtrFound = false; /***** Clear data *****/ - Ctr->InsCod = -1L; - Ctr->PlcCod = -1L; - Ctr->Status = (Ctr_Status_t) 0; + Ctr->InsCod = -1L; + Ctr->PlcCod = -1L; + Ctr->Status = (Ctr_Status_t) 0; Ctr->RequesterUsrCod = -1L; - Ctr->ShrtName[0] = '\0'; - Ctr->FullName[0] = '\0'; - Ctr->WWW[0] = '\0'; - Ctr->Degs.Num = 0; - Ctr->Degs.Lst = NULL; + Ctr->ShrtName[0] = '\0'; + Ctr->FullName[0] = '\0'; + Ctr->WWW[0] = '\0'; + Ctr->Degs.Num = 0; + Ctr->Degs.Lst = NULL; /***** Check if centre code is correct *****/ if (Ctr->CtrCod > 0) @@ -1990,6 +1990,7 @@ static void Ctr_EditingCentreConstructor (void) Ctr_EditingCtr->CtrCod = -1L; Ctr_EditingCtr->InsCod = -1L; Ctr_EditingCtr->PlcCod = -1L; + Ctr_EditingCtr->Status = (Ctr_Status_t) 0; Ctr_EditingCtr->RequesterUsrCod = -1L; Ctr_EditingCtr->ShrtName[0] = '\0'; Ctr_EditingCtr->FullName[0] = '\0'; diff --git a/swad_changelog.h b/swad_changelog.h index d73b7f561..b55e63dea 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -492,7 +492,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 19.112.7 (2020-01-05)" +#define Log_PLATFORM_VERSION "SWAD 19.112.8 (2020-01-05)" #define CSS_FILE "swad19.112.css" #define JS_FILE "swad19.91.1.js" /* @@ -500,8 +500,9 @@ ps2pdf source.ps destination.pdf // TODO: Impedir la creación y edición de proyectos si no son editables. // TODO: No se puede entrar con DNI '1' suponiendo que no tenga password ¿por qué? // TODO: Mapas más estrechos en móvil -// TODO: Quitar todos los EXTRA_DATA +// TODO: Quitar todos los EXTRA_DATA. + Version 19.112.8: Jan 05, 2020 Optimization in number of courses in a degree. (278396 lines) Version 19.112.7: Jan 05, 2020 Optimization in number of degrees in a centre. (278384 lines) Version 19.112.6: Jan 05, 2020 Optimization in number of courses in a centre. (278374 lines) Version 19.112.5: Jan 05, 2020 Optimization in number of users who claim to belong to a centre. (278361 lines) diff --git a/swad_chat.c b/swad_chat.c index 013cc679e..a59a77e1e 100644 --- a/swad_chat.c +++ b/swad_chat.c @@ -175,7 +175,7 @@ void Cht_ShowListOfAvailableChatRooms (void) { /* Get data of this degree */ Deg.DegCod = Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].DegCod; - if (!Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA)) + if (!Deg_GetDataOfDegreeByCod (&Deg)) Lay_ShowErrorAndExit ("Degree not found."); /* Link to the room of this degree */ @@ -521,7 +521,7 @@ void Cht_OpenChatWindow (void) /* Get data of this degree */ Deg.DegCod = Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].DegCod; - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Deg); snprintf (ThisRoomShortName,sizeof (ThisRoomShortName), "%s", diff --git a/swad_course.c b/swad_course.c index 9775835ee..a55ba9a5f 100644 --- a/swad_course.c +++ b/swad_course.c @@ -67,7 +67,7 @@ static struct Course *Crs_EditingCrs = NULL; // Static variable to keep the cour static void Crs_WriteListMyCoursesToSelectOne (void); -static void Crs_GetListCoursesInCurrentDegree (Crs_WhatCourses_t WhatCourses); +static void Crs_GetListCrssInCurrentDeg (Crs_WhatCourses_t WhatCourses); static void Crs_ListCourses (void); static bool Crs_CheckIfICanCreateCourses (void); static void Crs_PutIconsListCourses (void); @@ -309,7 +309,7 @@ static void Crs_WriteListMyCoursesToSelectOne (void) /***** Get data of this degree *****/ Deg.DegCod = Str_ConvertStrCodToLongCod (row[0]); - if (!Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA)) + if (!Deg_GetDataOfDegreeByCod (&Deg)) Lay_ShowErrorAndExit ("Degree not found."); /***** Write link to degree *****/ @@ -475,14 +475,30 @@ unsigned Crs_GetNumCrssInCtr (long CtrCod) /******************** Get number of courses in a degree **********************/ /*****************************************************************************/ +void Crs_FlushCacheNumCrssInDeg (void) + { + Gbl.Cache.NumCrssInDeg.DegCod = -1L; + Gbl.Cache.NumCrssInDeg.NumCrss = 0; + } + unsigned Crs_GetNumCrssInDeg (long DegCod) { - /***** Get number of courses in a degree from database *****/ - return + /***** 1. Fast check: Trivial case *****/ + if (DegCod <= 0) + return 0; + + /***** 2. Fast check: If cached... *****/ + if (DegCod == Gbl.Cache.NumCrssInDeg.DegCod) + return Gbl.Cache.NumCrssInDeg.NumCrss; + + /***** 3. Slow: number of courses in a degree from database *****/ + Gbl.Cache.NumCrssInDeg.DegCod = DegCod; + Gbl.Cache.NumCrssInDeg.NumCrss = (unsigned) DB_QueryCOUNT ("can not get the number of courses in a degree", "SELECT COUNT(*) FROM courses" " WHERE DegCod=%ld", DegCod); + return Gbl.Cache.NumCrssInDeg.NumCrss; } /*****************************************************************************/ @@ -578,7 +594,7 @@ void Crs_ShowCrssOfCurrentDeg (void) return; /***** Get list of courses in this degree *****/ - Crs_GetListCoursesInCurrentDegree (Crs_ALL_COURSES_EXCEPT_REMOVED); + Crs_GetListCrssInCurrentDeg (Crs_ALL_COURSES_EXCEPT_REMOVED); /***** Write menu to select country, institution, centre and degree *****/ Hie_WriteMenuHierarchy (); @@ -594,7 +610,7 @@ void Crs_ShowCrssOfCurrentDeg (void) /*************** Create a list with courses in current degree ****************/ /*****************************************************************************/ -static void Crs_GetListCoursesInCurrentDegree (Crs_WhatCourses_t WhatCourses) +static void Crs_GetListCrssInCurrentDeg (Crs_WhatCourses_t WhatCourses) { MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -790,7 +806,7 @@ static void Crs_ListCourses (void) { Frm_StartForm (ActEdiCrs); Btn_PutConfirmButton (Gbl.Hierarchy.Deg.Crss.Num ? Txt_Create_another_course : - Txt_Create_course); + Txt_Create_course); Frm_EndForm (); } @@ -954,10 +970,10 @@ static void Crs_EditCoursesInternal (void) extern const char *Txt_Courses_of_DEGREE_X; /***** Get list of degrees in this centre *****/ - Deg_GetListDegsOfCurrentCtr (); + Deg_GetListDegsInCurrentCtr (); /***** Get list of courses in this degree *****/ - Crs_GetListCoursesInCurrentDegree (Crs_ALL_COURSES_EXCEPT_REMOVED); + Crs_GetListCrssInCurrentDeg (Crs_ALL_COURSES_EXCEPT_REMOVED); /***** Write menu to select country, institution, centre and degree *****/ Hie_WriteMenuHierarchy (); @@ -2592,7 +2608,7 @@ static void Crs_WriteRowCrsData (unsigned NumCrs,MYSQL_ROW row,bool WriteColumnA /***** Get degree code (row[0]) *****/ if ((Deg.DegCod = Str_ConvertStrCodToLongCod (row[0])) < 0) Lay_ShowErrorAndExit ("Wrong code of degree."); - if (!Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA)) + if (!Deg_GetDataOfDegreeByCod (&Deg)) Lay_ShowErrorAndExit ("Degree not found."); /***** Get course code (row[1]) *****/ diff --git a/swad_course.h b/swad_course.h index f0293feea..99a2b6b0a 100644 --- a/swad_course.h +++ b/swad_course.h @@ -105,6 +105,7 @@ unsigned Crs_GetNumCrssInCty (long CtyCod); unsigned Crs_GetNumCrssInIns (long InsCod); void Crs_FlushCacheNumCrssInCtr (void); unsigned Crs_GetNumCrssInCtr (long CtrCod); +void Crs_FlushCacheNumCrssInDeg (void); unsigned Crs_GetNumCrssInDeg (long DegCod); unsigned Crs_GetNumCrssWithUsrs (Rol_Role_t Role,const char *SubQuery); diff --git a/swad_course_config.c b/swad_course_config.c index 3d1026436..67cd5eb7f 100644 --- a/swad_course_config.c +++ b/swad_course_config.c @@ -229,7 +229,7 @@ static void CrsCfg_Degree (bool PrintView,bool PutForm) if (PutForm) { /* Get list of degrees of the current centre */ - Deg_GetListDegsOfCurrentCtr (); + Deg_GetListDegsInCurrentCtr (); /* Put form to select degree */ Frm_StartForm (ActChgCrsDegCfg); @@ -493,7 +493,7 @@ void CrsCfg_ChangeCrsDeg (void) if (NewDeg.DegCod != Gbl.Hierarchy.Crs.DegCod) { /***** Get data of new degree *****/ - Deg_GetDataOfDegreeByCod (&NewDeg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&NewDeg); /***** If name of course was in database in the new degree... *****/ if (Crs_CheckIfCrsNameExistsInYearOfDeg ("ShortName",Gbl.Hierarchy.Crs.ShrtName,-1L, diff --git a/swad_degree.c b/swad_degree.c index be21dec9d..deada882a 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -177,7 +177,7 @@ void Deg_SeeDegWithPendingCrss (void) Gbl.ColorRows[Gbl.RowEvenOdd]; /* Get data of degree */ - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Deg); HTM_TR_Begin (NULL); @@ -310,7 +310,7 @@ void Deg_ShowDegsOfCurrentCtr (void) /***** Get list of centres and degrees *****/ Ctr_GetListCentres (Gbl.Hierarchy.Ins.InsCod); - Deg_GetListDegsOfCurrentCtr (); + Deg_GetListDegsInCurrentCtr (); /***** Write menu to select country, institution and centre *****/ Hie_WriteMenuHierarchy (); @@ -850,6 +850,7 @@ static void Deg_ListOneDegreeForSeeing (struct Degree *Deg,unsigned NumDeg) const char *TxtClassNormal; const char *TxtClassStrong; const char *BgColor; + unsigned NumCrss = Crs_GetNumCrssInDeg (Deg->DegCod); Deg_StatusTxt_t StatusTxt; /***** Get data of type of degree of this degree *****/ @@ -868,17 +869,17 @@ static void Deg_ListOneDegreeForSeeing (struct Degree *Deg,unsigned NumDeg) TxtClassStrong = "BT_LINK LT DAT_N"; } BgColor = (Deg->DegCod == Gbl.Hierarchy.Deg.DegCod) ? "LIGHT_BLUE" : - Gbl.ColorRows[Gbl.RowEvenOdd]; + Gbl.ColorRows[Gbl.RowEvenOdd]; HTM_TR_Begin (NULL); /***** Put tip if degree has courses *****/ HTM_TD_Begin ("class=\"%s CM %s\" title=\"%s\"", TxtClassNormal,BgColor, - Deg->Crss.Num ? Txt_DEGREE_With_courses : - Txt_DEGREE_Without_courses); - HTM_Txt (Deg->Crss.Num ? "✓" : - " "); + NumCrss ? Txt_DEGREE_With_courses : + Txt_DEGREE_Without_courses); + HTM_Txt (NumCrss ? "✓" : + " "); HTM_TD_End (); /***** Number of degree in this list *****/ @@ -899,7 +900,7 @@ static void Deg_ListOneDegreeForSeeing (struct Degree *Deg,unsigned NumDeg) /***** Current number of courses in this degree *****/ HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor); - HTM_Unsigned (Deg->Crss.Num); + HTM_Unsigned (NumCrss); HTM_TD_End (); /***** Degree status *****/ @@ -937,7 +938,7 @@ static void Deg_EditDegreesInternal (void) extern const char *Txt_No_types_of_degree; /***** Get list of degrees in the current centre *****/ - Deg_GetListDegsOfCurrentCtr (); + Deg_GetListDegsInCurrentCtr (); /***** Get list of degree types *****/ DT_GetListDegreeTypes (Hie_SYS,DT_ORDER_BY_DEGREE_TYPE); @@ -1061,7 +1062,7 @@ void Deg_GetListAllDegsWithStds (struct ListDegrees *Degs) /************ Get a list with the degrees of the current centre **************/ /*****************************************************************************/ -void Deg_GetListDegsOfCurrentCtr (void) +void Deg_GetListDegsInCurrentCtr (void) { MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -1096,9 +1097,6 @@ void Deg_GetListDegsOfCurrentCtr (void) /* Get next degree */ row = mysql_fetch_row (mysql_res); Deg_GetDataOfDegreeFromRow (Deg,row); - - /* Get number of courses in this degree */ - Deg->Crss.Num = Crs_GetNumCrssInDeg (Deg->DegCod); } } else @@ -1224,10 +1222,10 @@ void Deg_RemoveDegree (void) Deg_EditingDeg->DegCod = Deg_GetAndCheckParamOtherDegCod (1); /***** Get data of degree *****/ - Deg_GetDataOfDegreeByCod (Deg_EditingDeg,Deg_GET_EXTRA_DATA); + Deg_GetDataOfDegreeByCod (Deg_EditingDeg); /***** Check if this degree has courses *****/ - if (Deg_EditingDeg->Crss.Num) // Degree has courses ==> don't remove + if (Crs_GetNumCrssInDeg (Deg_EditingDeg->DegCod)) // Degree has courses ==> don't remove Ale_CreateAlert (Ale_WARNING,NULL, Txt_To_remove_a_degree_you_must_first_remove_all_courses_in_the_degree); else // Degree has no courses ==> remove it @@ -1282,22 +1280,22 @@ long Deg_GetAndCheckParamOtherDegCod (long MinCodAllowed) /*****************************************************************************/ // Returns true if degree found -bool Deg_GetDataOfDegreeByCod (struct Degree *Deg, - Deg_GetExtraData_t GetExtraData) +bool Deg_GetDataOfDegreeByCod (struct Degree *Deg) { MYSQL_RES *mysql_res; MYSQL_ROW row; bool DegFound = false; /***** Clear data *****/ - Deg->CtrCod = -1L; - Deg->DegTypCod = -1L; - Deg->Status = (Deg_Status_t) 0; + Deg->CtrCod = -1L; + Deg->DegTypCod = -1L; + Deg->Status = (Deg_Status_t) 0; Deg->RequesterUsrCod = -1L; - Deg->ShrtName[0] = '\0'; - Deg->FullName[0] = '\0'; - Deg->WWW[0] = '\0'; - Deg->Crss.Lst = NULL; + Deg->ShrtName[0] = '\0'; + Deg->FullName[0] = '\0'; + Deg->WWW[0] = '\0'; + Deg->Crss.Num = 0; + Deg->Crss.Lst = NULL; /***** Check if degree code is correct *****/ if (Deg->DegCod > 0) @@ -1313,11 +1311,6 @@ bool Deg_GetDataOfDegreeByCod (struct Degree *Deg, row = mysql_fetch_row (mysql_res); Deg_GetDataOfDegreeFromRow (Deg,row); - /* Get extra data */ - if (GetExtraData == Deg_GET_EXTRA_DATA) - /* Get number of courses in this degree */ - Deg->Crss.Num = Crs_GetNumCrssInDeg (Deg->DegCod); - /* Set return value */ DegFound = true; } @@ -1519,6 +1512,9 @@ void Deg_RemoveDegreeCompletely (long DegCod) "DELETE FROM degrees WHERE DegCod=%ld", DegCod); + /***** Flush caches *****/ + Crs_FlushCacheNumCrssInDeg (); + /***** Delete all the degrees in sta_degrees table not present in degrees table *****/ Pho_RemoveObsoleteStatDegrees (); } @@ -1583,7 +1579,7 @@ void Deg_RenameDegree (struct Degree *Deg,Cns_ShrtOrFullName_t ShrtOrFullName) Par_GetParToText (ParamName,NewDegName,MaxBytes); /***** Get data of degree *****/ - Deg_GetDataOfDegreeByCod (Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (Deg); /***** Check if new name is empty *****/ if (NewDegName[0]) @@ -1668,7 +1664,7 @@ void Deg_ChangeDegreeType (void) NewDegTypCod = DT_GetAndCheckParamOtherDegTypCod (1); /***** Get data of degree *****/ - Deg_GetDataOfDegreeByCod (Deg_EditingDeg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (Deg_EditingDeg); /***** Update the table of degrees changing old type by new type *****/ DB_QueryUPDATE ("can not update the type of a degree", @@ -1703,7 +1699,7 @@ void Deg_ChangeDegWWW (void) Par_GetParToText ("WWW",NewWWW,Cns_MAX_BYTES_WWW); /***** Get data of degree *****/ - Deg_GetDataOfDegreeByCod (Deg_EditingDeg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (Deg_EditingDeg); /***** Check if new WWW is empty *****/ if (NewWWW[0]) @@ -1764,7 +1760,7 @@ void Deg_ChangeDegStatus (void) Status = Deg_GetStatusBitsFromStatusTxt (StatusTxt); // New status /***** Get data of degree *****/ - Deg_GetDataOfDegreeByCod (Deg_EditingDeg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (Deg_EditingDeg); /***** Update status in table of degrees *****/ DB_QueryUPDATE ("can not update the status of a degree", @@ -1984,7 +1980,7 @@ void Deg_ListDegsFound (MYSQL_RES **mysql_res,unsigned NumDegs) Deg_PutHeadDegreesForSeeing (); /***** List the degrees (one row per degree) *****/ - for (NumDeg = 1; + for (NumDeg = 1; NumDeg <= NumDegs; NumDeg++) { @@ -1995,7 +1991,7 @@ void Deg_ListDegsFound (MYSQL_RES **mysql_res,unsigned NumDegs) Deg.DegCod = Str_ConvertStrCodToLongCod (row[0]); /* Get data of degree */ - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_EXTRA_DATA); + Deg_GetDataOfDegreeByCod (&Deg); /* Write data of this degree */ Deg_ListOneDegreeForSeeing (&Deg,NumDeg); @@ -2027,7 +2023,7 @@ static void Deg_EditingDegreeConstructor (void) Deg_EditingDeg->DegCod = -1L; Deg_EditingDeg->DegTypCod = -1L; Deg_EditingDeg->CtrCod = -1L; - Deg_EditingDeg->Status = 0; + Deg_EditingDeg->Status = (Deg_Status_t) 0; Deg_EditingDeg->RequesterUsrCod = -1L; Deg_EditingDeg->ShrtName[0] = '\0'; Deg_EditingDeg->FullName[0] = '\0'; diff --git a/swad_degree.h b/swad_degree.h index 1ebf2a5a2..c538531ae 100644 --- a/swad_degree.h +++ b/swad_degree.h @@ -89,12 +89,6 @@ struct ListDegrees struct Degree *Lst; // List of degrees }; -typedef enum - { - Deg_GET_BASIC_DATA, - Deg_GET_EXTRA_DATA, - } Deg_GetExtraData_t; - /*****************************************************************************/ /***************************** Public prototypes *****************************/ /*****************************************************************************/ @@ -115,7 +109,7 @@ void Deg_EditDegrees (void); void Deg_PutIconToViewDegrees (void); void Deg_GetListAllDegsWithStds (struct ListDegrees *Degs); -void Deg_GetListDegsOfCurrentCtr (void); +void Deg_GetListDegsInCurrentCtr (void); void Deg_FreeListDegs (struct ListDegrees *Degs); void Deg_RecFormReqDeg (void); @@ -125,8 +119,7 @@ void Deg_RemoveDegree (void); void Deg_PutParamDegCod (long DegCod); long Deg_GetAndCheckParamOtherDegCod (long MinCodAllowed); -bool Deg_GetDataOfDegreeByCod (struct Degree *Deg, - Deg_GetExtraData_t GetExtraData); +bool Deg_GetDataOfDegreeByCod (struct Degree *Deg); void Deg_GetShortNameOfDegreeByCod (struct Degree *Deg); long Deg_GetCtrCodOfDegreeByCod (long DegCod); long Deg_GetInsCodOfDegreeByCod (long DegCod); diff --git a/swad_enrolment.c b/swad_enrolment.c index 959f16f66..ce92058a7 100644 --- a/swad_enrolment.c +++ b/swad_enrolment.c @@ -2822,7 +2822,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected) /***** Link to course *****/ Crs_GetDataOfCourseByCod (&Crs,Crs_GET_BASIC_DATA); Deg.DegCod = Crs.DegCod; - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Deg); HTM_TD_Begin ("class=\"DAT LT\""); Frm_StartFormGoTo (ActSeeCrsInf); Crs_PutParamCrsCod (Crs.CrsCod); diff --git a/swad_exam.c b/swad_exam.c index bd33ab67e..90166bad8 100644 --- a/swad_exam.c +++ b/swad_exam.c @@ -1611,7 +1611,7 @@ static void Exa_GetNotifContentExamAnnouncement (char **ContentStr) /***** Get data of degree *****/ Deg.DegCod = Crs.DegCod; - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Deg); /***** Get data of institution *****/ Ins.InsCod = Deg_GetInsCodOfDegreeByCod (Deg.DegCod); diff --git a/swad_file_browser.c b/swad_file_browser.c index 843c83154..a8e1d1126 100644 --- a/swad_file_browser.c +++ b/swad_file_browser.c @@ -6882,7 +6882,7 @@ static void Brw_WriteCurrentClipboard (void) break; case Brw_ADMI_DOC_DEG: Deg.DegCod = Gbl.FileBrowser.Clipboard.Cod; - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Deg); snprintf (TxtClipboardZone,sizeof (TxtClipboardZone), "%s, %s %s", Txt_documents_management_area, @@ -6890,7 +6890,7 @@ static void Brw_WriteCurrentClipboard (void) break; case Brw_ADMI_SHR_DEG: Deg.DegCod = Gbl.FileBrowser.Clipboard.Cod; - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Deg); snprintf (TxtClipboardZone,sizeof (TxtClipboardZone), "%s, %s %s", Txt_shared_files_area, @@ -7891,7 +7891,7 @@ static void Brw_PasteClipboard (void) case Brw_ADMI_DOC_DEG: case Brw_ADMI_SHR_DEG: Deg.DegCod = Gbl.FileBrowser.Clipboard.Cod; - if (Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA)) + if (Deg_GetDataOfDegreeByCod (&Deg)) snprintf (PathOrg,sizeof (PathOrg), "%s/%02u/%u/%s", Cfg_PATH_DEG_PRIVATE, @@ -11062,7 +11062,7 @@ void Brw_GetCrsGrpFromFileMetadata (Brw_FileBrowser_t FileBrowser,long Cod, *GrpCod = -1L; *CrsCod = -1L; *DegCod = Deg.DegCod = Cod; - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Deg); *CtrCod = Ctr.CtrCod = Deg.CtrCod; Ctr_GetDataOfCentreByCod (&Ctr); *InsCod = Ctr.InsCod; @@ -11078,7 +11078,7 @@ void Brw_GetCrsGrpFromFileMetadata (Brw_FileBrowser_t FileBrowser,long Cod, *CrsCod = Crs.CrsCod = Cod; Crs_GetDataOfCourseByCod (&Crs,Crs_GET_BASIC_DATA); *DegCod = Deg.DegCod = Crs.DegCod; - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Deg); *CtrCod = Ctr.CtrCod = Deg.CtrCod; Ctr_GetDataOfCentreByCod (&Ctr); *InsCod = Ctr.InsCod; @@ -11093,7 +11093,7 @@ void Brw_GetCrsGrpFromFileMetadata (Brw_FileBrowser_t FileBrowser,long Cod, *CrsCod = Crs.CrsCod = GrpDat.CrsCod; Crs_GetDataOfCourseByCod (&Crs,Crs_GET_BASIC_DATA); *DegCod = Deg.DegCod = Crs.DegCod; - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Deg); *CtrCod = Ctr.CtrCod = Deg.CtrCod; Ctr_GetDataOfCentreByCod (&Ctr); *InsCod = Ctr.InsCod; @@ -11105,7 +11105,7 @@ void Brw_GetCrsGrpFromFileMetadata (Brw_FileBrowser_t FileBrowser,long Cod, *CrsCod = Crs.CrsCod = Prj_GetCourseOfProject (Cod); Crs_GetDataOfCourseByCod (&Crs,Crs_GET_BASIC_DATA); *DegCod = Deg.DegCod = Crs.DegCod; - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Deg); *CtrCod = Ctr.CtrCod = Deg.CtrCod; Ctr_GetDataOfCentreByCod (&Ctr); *InsCod = Ctr.InsCod; diff --git a/swad_forum.c b/swad_forum.c index d1610c447..e793df847 100644 --- a/swad_forum.c +++ b/swad_forum.c @@ -2191,14 +2191,14 @@ void For_SetForumName (struct Forum *Forum, break; case For_FORUM_DEGREE_USRS: Deg.DegCod = Forum->Location; - if (!Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA)) + if (!Deg_GetDataOfDegreeByCod (&Deg)) Lay_ShowErrorAndExit ("Degree not found."); Str_Copy (ForumName,Deg.ShrtName, For_MAX_BYTES_FORUM_NAME); break; case For_FORUM_DEGREE_TCHS: Deg.DegCod = Forum->Location; - if (!Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA)) + if (!Deg_GetDataOfDegreeByCod (&Deg)) Lay_ShowErrorAndExit ("Degree not found."); snprintf (ForumName,For_MAX_BYTES_FORUM_NAME + 1, "%s%s",Deg.ShrtName, diff --git a/swad_global.c b/swad_global.c index 71dafbdae..a79cdc9ec 100644 --- a/swad_global.c +++ b/swad_global.c @@ -414,6 +414,7 @@ void Gbl_InitializeGlobals (void) Ins_FlushCacheFullNameAndCtyOfInstitution (); Deg_FlushCacheNumDegsInCtr (); Crs_FlushCacheNumCrssInCtr (); + Crs_FlushCacheNumCrssInDeg (); Usr_FlushCacheNumUsrsWhoClaimToBelongToCtr (); Usr_FlushCacheNumUsrsInCrssOfCtr (); Usr_FlushCacheUsrIsSuperuser (); diff --git a/swad_global.h b/swad_global.h index 848a2f174..b261b4ad2 100644 --- a/swad_global.h +++ b/swad_global.h @@ -782,6 +782,11 @@ struct Globals long CtrCod; unsigned NumCrss; } NumCrssInCtr; + struct + { + long DegCod; + unsigned NumCrss; + } NumCrssInDeg; struct { long CtrCod; diff --git a/swad_hierarchy.c b/swad_hierarchy.c index 6f9f7c685..240357ff5 100644 --- a/swad_hierarchy.c +++ b/swad_hierarchy.c @@ -535,8 +535,7 @@ void Hie_InitHierarchy (void) /***** If degree code is available, get degree data *****/ if (Gbl.Hierarchy.Deg.DegCod > 0) { - if (Deg_GetDataOfDegreeByCod (&Gbl.Hierarchy.Deg, // Degree found - Deg_GET_EXTRA_DATA)) // Get extra data because they may be needed later + if (Deg_GetDataOfDegreeByCod (&Gbl.Hierarchy.Deg)) // Degree found { Gbl.Hierarchy.Ctr.CtrCod = Gbl.Hierarchy.Deg.CtrCod; Gbl.Hierarchy.Ins.InsCod = Deg_GetInsCodOfDegreeByCod (Gbl.Hierarchy.Deg.DegCod); @@ -548,7 +547,7 @@ void Hie_InitHierarchy (void) /***** If centre code is available, get centre data *****/ if (Gbl.Hierarchy.Ctr.CtrCod > 0) { - if (Ctr_GetDataOfCentreByCod (&Gbl.Hierarchy.Ctr)) // Degree found + if (Ctr_GetDataOfCentreByCod (&Gbl.Hierarchy.Ctr)) // Centre found Gbl.Hierarchy.Ins.InsCod = Gbl.Hierarchy.Ctr.InsCod; else Hie_ResetHierarchy (); @@ -762,7 +761,7 @@ void Hie_GetAndWriteInsCtrDegAdminBy (long UsrCod,unsigned ColSpan) if (Deg.DegCod > 0) { /* Get data of degree */ - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Deg); /* Write degree logo and name */ Deg_DrawDegreeLogoAndNameWithLink (&Deg,ActSeeDegInf, diff --git a/swad_layout.c b/swad_layout.c index 861aa57b0..917546868 100644 --- a/swad_layout.c +++ b/swad_layout.c @@ -1557,7 +1557,7 @@ void Lay_WriteHeaderClassPhoto (bool PrintView,bool DrawingClassPhoto, /***** Get data of degree *****/ Deg.DegCod = DegCod; - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Deg); /***** Get data of course *****/ Crs.CrsCod = CrsCod; diff --git a/swad_notification.c b/swad_notification.c index b3f03706c..45ac87a95 100644 --- a/swad_notification.c +++ b/swad_notification.c @@ -411,7 +411,7 @@ void Ntf_ShowMyNotifications (void) /* Get degree code (row[4]) */ Deg.DegCod = Str_ConvertStrCodToLongCod (row[4]); - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Deg); /* Get course code (row[5]) */ Crs.CrsCod = Str_ConvertStrCodToLongCod (row[5]); @@ -1658,7 +1658,7 @@ static void Ntf_SendPendingNotifByEMailToOneUsr (struct UsrData *ToUsrDat,unsign /* Get degree code (row[4]) */ Deg.DegCod = Str_ConvertStrCodToLongCod (row[4]); - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Deg); /* Get course code (row[5]) */ Crs.CrsCod = Str_ConvertStrCodToLongCod (row[5]); diff --git a/swad_photo.c b/swad_photo.c index 90a7a43d9..e1df055d4 100644 --- a/swad_photo.c +++ b/swad_photo.c @@ -2010,7 +2010,7 @@ static void Pho_PutLinkToCalculateDegreeStats (void) Deg_GetListAllDegsWithStds (&Degs); /***** Get data of the degree from database *****/ - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Deg); /***** Contextual menu *****/ Mnu_ContextMenuBegin (); @@ -2153,7 +2153,7 @@ static void Pho_ShowOrPrintClassPhotoDegrees (Pho_AvgPhotoSeeOrPrint_t SeeOrPrin Lay_ShowErrorAndExit ("Wrong code of degree."); /* Get data of degree */ - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Deg); /* Get number of students and number of students with photo in this degree */ Pho_GetNumStdsInDegree (Deg.DegCod,Usr_SEX_ALL,&NumStds,&NumStdsWithPhoto); @@ -2246,7 +2246,7 @@ static void Pho_ShowOrPrintListDegrees (Pho_AvgPhotoSeeOrPrint_t SeeOrPrint) Lay_ShowErrorAndExit ("Wrong code of degree."); /* Get data of degree */ - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Deg); HTM_TR_Begin (NULL); diff --git a/swad_report.c b/swad_report.c index 9e03ac40f..18b9e7806 100644 --- a/swad_report.c +++ b/swad_report.c @@ -1165,7 +1165,7 @@ static void Rep_WriteRowCrsData (long CrsCod,Rol_Role_t Role, /***** Get degree data *****/ Deg.DegCod = Crs.DegCod; - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Deg); /***** Start row *****/ fprintf (Gbl.F.Rep,"
  • "); diff --git a/swad_statistic.c b/swad_statistic.c index 11c4c3516..3fc161cbe 100644 --- a/swad_statistic.c +++ b/swad_statistic.c @@ -3552,7 +3552,7 @@ static void Sta_WriteDegree (long DegCod) { /***** Get data of degree *****/ Deg.DegCod = DegCod; - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Deg); /***** Title in cell *****/ HTM_TD_Begin ("class=\"LOG LM\" title=\"%s\"",Deg.FullName); diff --git a/swad_timeline.c b/swad_timeline.c index 4df61692a..d912c140b 100644 --- a/swad_timeline.c +++ b/swad_timeline.c @@ -1623,7 +1623,7 @@ static void TL_WriteNote (const struct TL_Note *SocNot, case TL_NOTE_DEG_SHA_PUB_FILE: /* Get degree data */ Deg.DegCod = SocNot->HieCod; - Deg_GetDataOfDegreeByCod (&Deg,Deg_GET_BASIC_DATA); + Deg_GetDataOfDegreeByCod (&Deg); break; case TL_NOTE_CRS_DOC_PUB_FILE: case TL_NOTE_CRS_SHA_PUB_FILE: