From 3cc0c2c779f78df37096636e45aa37258c13c968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Mon, 6 Jan 2020 18:43:48 +0100 Subject: [PATCH] Version19.112.15 --- swad_changelog.h | 6 ++++-- swad_course.c | 20 ++++++++++++++++++-- swad_course.h | 1 + swad_degree.c | 20 ++++++++++++++++++-- swad_degree.h | 1 + swad_global.c | 4 +++- swad_global.h | 10 ++++++++++ swad_institution.c | 21 +++++---------------- swad_institution.h | 2 -- 9 files changed, 60 insertions(+), 25 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index ef2d7b65d..1c2944d70 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.13 (2020-01-06)" +#define Log_PLATFORM_VERSION "SWAD 19.112.15 (2020-01-06)" #define CSS_FILE "swad19.112.css" #define JS_FILE "swad19.91.1.js" /* @@ -502,7 +502,9 @@ ps2pdf source.ps destination.pdf // TODO: Mapas más estrechos en móvil // TODO: Quitar todos los EXTRA_DATA. - Version 19.112.13:Jan 06, 2020 Optimization in number of departments of an institution. (278535 lines) + Version 19.112.15:Jan 06, 2020 Optimization in number of degrees in an institution. (278567 lines) + Version 19.112.14:Jan 06, 2020 Optimization in number of courses in an institution. (278555 lines) + Version 19.112.13:Jan 06, 2020 Optimization in number of departments in an institution. (278535 lines) Version 19.112.12:Jan 06, 2020 Optimization in number of users who claim to belong to an institution. (278519 lines) Version 19.112.11:Jan 06, 2020 Optimization in number of users in courses of an institution. (278486 lines) Version 19.112.10:Jan 06, 2020 Optimization in number of users in courses of a degree. (278468 lines) diff --git a/swad_course.c b/swad_course.c index 68d08fa8d..d84ed48d4 100644 --- a/swad_course.c +++ b/swad_course.c @@ -427,10 +427,25 @@ unsigned Crs_GetNumCrssInCty (long CtyCod) /**************** Get number of courses in an institution ********************/ /*****************************************************************************/ +void Crs_FlushCacheNumCrssInIns (void) + { + Gbl.Cache.NumCrssInIns.InsCod = -1L; + Gbl.Cache.NumCrssInIns.NumCrss = 0; + } + unsigned Crs_GetNumCrssInIns (long InsCod) { - /***** Get number of courses in a degree from database *****/ - return + /***** 1. Fast check: Trivial case *****/ + if (InsCod <= 0) + return 0; + + /***** 2. Fast check: If cached... *****/ + if (InsCod == Gbl.Cache.NumCrssInIns.InsCod) + return Gbl.Cache.NumCrssInIns.NumCrss; + + /***** 3. Slow: number of courses in an institution from database *****/ + Gbl.Cache.NumCrssInIns.InsCod = InsCod; + Gbl.Cache.NumCrssInIns.NumCrss = (unsigned) DB_QueryCOUNT ("can not get the number of courses" " in an institution", "SELECT COUNT(*) FROM centres,degrees,courses" @@ -438,6 +453,7 @@ unsigned Crs_GetNumCrssInIns (long InsCod) " AND centres.CtrCod=degrees.CtrCod" " AND degrees.DegCod=courses.DegCod", InsCod); + return Gbl.Cache.NumCrssInIns.NumCrss; } /*****************************************************************************/ diff --git a/swad_course.h b/swad_course.h index cd6a5f419..dd4311b52 100644 --- a/swad_course.h +++ b/swad_course.h @@ -95,6 +95,7 @@ void Crs_ShowIntroduction (void); unsigned Crs_GetNumCrssTotal (void); unsigned Crs_GetNumCrssInCty (long CtyCod); +void Crs_FlushCacheNumCrssInIns (void); unsigned Crs_GetNumCrssInIns (long InsCod); void Crs_FlushCacheNumCrssInCtr (void); unsigned Crs_GetNumCrssInCtr (long CtrCod); diff --git a/swad_degree.c b/swad_degree.c index e17840c5c..c2bb7e898 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -1876,16 +1876,32 @@ unsigned Deg_GetNumDegsInCty (long InsCod) /****************** Get number of degrees in an institution ******************/ /*****************************************************************************/ +void Deg_FlushCacheNumDegsInIns (void) + { + Gbl.Cache.NumDegsInIns.InsCod = -1L; + Gbl.Cache.NumDegsInIns.NumDegs = 0; + } + unsigned Deg_GetNumDegsInIns (long InsCod) { - /***** Get number of degrees in an institution from database *****/ - return + /***** 1. Fast check: Trivial case *****/ + if (InsCod <= 0) + return 0; + + /***** 2. Fast check: If cached... *****/ + if (InsCod == Gbl.Cache.NumDegsInIns.InsCod) + return Gbl.Cache.NumDegsInIns.NumDegs; + + /***** 3. Slow: number of degrees in an institution from database *****/ + Gbl.Cache.NumDegsInIns.InsCod = InsCod; + Gbl.Cache.NumDegsInIns.NumDegs = (unsigned) DB_QueryCOUNT ("can not get the number of degrees" " in an institution", "SELECT COUNT(*) FROM centres,degrees" " WHERE centres.InsCod=%ld" " AND centres.CtrCod=degrees.CtrCod", InsCod); + return Gbl.Cache.NumDegsInIns.NumDegs; } /*****************************************************************************/ diff --git a/swad_degree.h b/swad_degree.h index c538531ae..8faa88d69 100644 --- a/swad_degree.h +++ b/swad_degree.h @@ -141,6 +141,7 @@ void Deg_RemoveLogo (void); unsigned Deg_GetNumDegsTotal (void); unsigned Deg_GetNumDegsInCty (long InsCod); +void Deg_FlushCacheNumDegsInIns (void); unsigned Deg_GetNumDegsInIns (long InsCod); void Deg_FlushCacheNumDegsInCtr (void); unsigned Deg_GetNumDegsInCtr (long CtrCod); diff --git a/swad_global.c b/swad_global.c index 52f9eb5cd..af9612582 100644 --- a/swad_global.c +++ b/swad_global.c @@ -220,7 +220,8 @@ void Gbl_InitializeGlobals (void) Gbl.Hierarchy.Ins.ShrtName[0] = '\0'; Gbl.Hierarchy.Ins.FullName[0] = '\0'; Gbl.Hierarchy.Ins.WWW[0] = '\0'; - Gbl.Hierarchy.Ins.Ctrs.Num = Gbl.Hierarchy.Ins.NumDegs = 0; + Gbl.Hierarchy.Ins.Ctrs.Num = 0; + Gbl.Hierarchy.Ins.Ctrs.Lst = NULL; Gbl.Hierarchy.Ctr.ShrtName[0] = '\0'; Gbl.Hierarchy.Ctr.FullName[0] = '\0'; @@ -413,6 +414,7 @@ void Gbl_InitializeGlobals (void) Ins_FlushCacheFullNameAndCtyOfInstitution (); Dpt_FlushCacheNumDptsInIns (); Deg_FlushCacheNumDegsInCtr (); + Crs_FlushCacheNumCrssInIns (); Crs_FlushCacheNumCrssInCtr (); Crs_FlushCacheNumCrssInDeg (); Usr_FlushCacheNumUsrsWhoClaimToBelongToIns (); diff --git a/swad_global.h b/swad_global.h index ecba7ac05..607f24248 100644 --- a/swad_global.h +++ b/swad_global.h @@ -777,11 +777,21 @@ struct Globals long InsCod; unsigned NumDpts; } NumDptsInIns; + struct + { + long InsCod; + unsigned NumDegs; + } NumDegsInIns; struct { long CtrCod; unsigned NumDegs; } NumDegsInCtr; + struct + { + long InsCod; + unsigned NumCrss; + } NumCrssInIns; struct { long CtrCod; diff --git a/swad_institution.c b/swad_institution.c index 53a75ef43..6e4220d65 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -412,12 +412,12 @@ static void Ins_ListOneInstitutionForSeeing (struct Instit *Ins,unsigned NumIns) /* Number of degrees in this institution */ HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor); - HTM_Unsigned (Ins->NumDegs); + HTM_Unsigned (Deg_GetNumDegsInIns (Ins->InsCod)); HTM_TD_End (); /* Number of courses in this institution */ HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor); - HTM_Unsigned (Ins->NumCrss); + HTM_Unsigned (Crs_GetNumCrssInIns (Ins->InsCod)); HTM_TD_End (); /* Number of departments in this institution */ @@ -698,17 +698,11 @@ void Ins_GetListInstitutions (long CtyCod,Ins_GetExtraData_t GetExtraData) switch (GetExtraData) { case Ins_GET_BASIC_DATA: - Ins->Ctrs.Num = Ins->NumDegs = Ins->NumCrss = 0; + Ins->Ctrs.Num = 0; break; case Ins_GET_EXTRA_DATA: /* Get number of centres in this institution */ Ins->Ctrs.Num = Ctr_GetNumCtrsInIns (Ins->InsCod); - - /* Get number of degrees in this institution */ - Ins->NumDegs = Deg_GetNumDegsInIns (Ins->InsCod); - - /* Get number of degrees in this institution */ - Ins->NumCrss = Crs_GetNumCrssInIns (Ins->InsCod); break; } } @@ -756,7 +750,7 @@ bool Ins_GetDataOfInstitutionByCod (struct Instit *Ins, Ins->ShrtName[0] = Ins->FullName[0] = Ins->WWW[0] = '\0'; - Ins->Ctrs.Num = Ins->NumDegs = Ins->NumCrss = 0; + Ins->Ctrs.Num = 0; /***** Check if institution code is correct *****/ if (Ins->InsCod > 0) @@ -794,14 +788,9 @@ bool Ins_GetDataOfInstitutionByCod (struct Instit *Ins, /* Get extra data */ if (GetExtraData == Ins_GET_EXTRA_DATA) - { /* Get number of centres in this institution */ Ins->Ctrs.Num = Ctr_GetNumCtrsInIns (Ins->InsCod); - /* Get number of degrees in this institution */ - Ins->NumDegs = Deg_GetNumDegsInIns (Ins->InsCod); - } - /* Set return value */ InsFound = true; } @@ -1354,6 +1343,7 @@ void Ins_RemoveInstitution (void) Ins_FlushCacheShortNameOfInstitution (); Ins_FlushCacheFullNameAndCtyOfInstitution (); Dpt_FlushCacheNumDptsInIns (); + Crs_FlushCacheNumCrssInIns (); Usr_FlushCacheNumUsrsWhoClaimToBelongToIns (); Usr_FlushCacheNumUsrsInCrssOfIns (); @@ -2034,7 +2024,6 @@ static void Ins_EditingInstitutionConstructor (void) Ins_EditingIns->Ctrs.Num = 0; Ins_EditingIns->Ctrs.Lst = NULL; Ins_EditingIns->Ctrs.SelectedOrder = Ctr_ORDER_DEFAULT; - Ins_EditingIns->NumDegs = 0; } static void Ins_EditingInstitutionDestructor (void) diff --git a/swad_institution.h b/swad_institution.h index 5eb82ffe3..da09b8d64 100644 --- a/swad_institution.h +++ b/swad_institution.h @@ -71,8 +71,6 @@ struct Instit struct Centre *Lst; // List of centres Ctr_Order_t SelectedOrder; } Ctrs; - unsigned NumDegs; - unsigned NumCrss; }; #define Ins_NUM_ORDERS 2