From 8f487eef7dcb30db9c762445c91f9e58e00d40ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Mon, 6 Jan 2020 18:27:43 +0100 Subject: [PATCH] Version19.112.13 --- swad_changelog.h | 3 ++- swad_department.c | 20 ++++++++++++++++++-- swad_department.h | 1 + swad_global.c | 3 ++- swad_global.h | 5 +++++ swad_institution.c | 14 ++++---------- swad_institution.h | 1 - 7 files changed, 32 insertions(+), 15 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index 6b406864..ef2d7b65 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.12 (2020-01-06)" +#define Log_PLATFORM_VERSION "SWAD 19.112.13 (2020-01-06)" #define CSS_FILE "swad19.112.css" #define JS_FILE "swad19.91.1.js" /* @@ -502,6 +502,7 @@ 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.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_department.c b/swad_department.c index fced855f..3322f12f 100644 --- a/swad_department.c +++ b/swad_department.c @@ -1058,15 +1058,31 @@ unsigned Dpt_GetTotalNumberOfDepartments (void) /**************** Get number of departments in a institution *****************/ /*****************************************************************************/ +void Dpt_FlushCacheNumDptsInIns (void) + { + Gbl.Cache.NumDptsInIns.InsCod = -1L; + Gbl.Cache.NumDptsInIns.NumDpts = 0; + } + unsigned Dpt_GetNumDptsInIns (long InsCod) { - /***** Get departments 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.NumDptsInIns.InsCod) + return Gbl.Cache.NumDptsInIns.NumDpts; + + /***** 3. Slow: number of departments of an institution from database *****/ + Gbl.Cache.NumDptsInIns.InsCod = InsCod; + Gbl.Cache.NumDptsInIns.NumDpts = (unsigned) DB_QueryCOUNT ("can not get number of departments" " in an institution", "SELECT COUNT(*) FROM departments" " WHERE InsCod=%ld", InsCod); + return Gbl.Cache.NumDptsInIns.NumDpts; } /*****************************************************************************/ diff --git a/swad_department.h b/swad_department.h index 13958851..91297df8 100644 --- a/swad_department.h +++ b/swad_department.h @@ -73,6 +73,7 @@ void Dpt_ContEditAfterChgDpt (void); void Dpt_RecFormNewDpt (void); unsigned Dpt_GetTotalNumberOfDepartments (void); +void Dpt_FlushCacheNumDptsInIns (void); unsigned Dpt_GetNumDptsInIns (long InsCod); void Dpt_WriteSelectorDepartment (long InsCod,long DptCod, diff --git a/swad_global.c b/swad_global.c index 2fa3df8f..52f9eb5c 100644 --- a/swad_global.c +++ b/swad_global.c @@ -220,7 +220,7 @@ 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.NumDpts = Gbl.Hierarchy.Ins.NumDegs = 0; + Gbl.Hierarchy.Ins.Ctrs.Num = Gbl.Hierarchy.Ins.NumDegs = 0; Gbl.Hierarchy.Ctr.ShrtName[0] = '\0'; Gbl.Hierarchy.Ctr.FullName[0] = '\0'; @@ -411,6 +411,7 @@ void Gbl_InitializeGlobals (void) Cty_FlushCacheCountryName (); Ins_FlushCacheShortNameOfInstitution (); Ins_FlushCacheFullNameAndCtyOfInstitution (); + Dpt_FlushCacheNumDptsInIns (); Deg_FlushCacheNumDegsInCtr (); Crs_FlushCacheNumCrssInCtr (); Crs_FlushCacheNumCrssInDeg (); diff --git a/swad_global.h b/swad_global.h index 0620dd3d..ecba7ac0 100644 --- a/swad_global.h +++ b/swad_global.h @@ -772,6 +772,11 @@ struct Globals char ShrtName[Hie_MAX_BYTES_SHRT_NAME + 1]; char CtyName[Hie_MAX_BYTES_FULL_NAME + 1]; } InstitutionShrtNameAndCty; + struct + { + long InsCod; + unsigned NumDpts; + } NumDptsInIns; struct { long CtrCod; diff --git a/swad_institution.c b/swad_institution.c index ca2d5de9..53a75ef4 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -422,7 +422,7 @@ static void Ins_ListOneInstitutionForSeeing (struct Instit *Ins,unsigned NumIns) /* Number of departments in this institution */ HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor); - HTM_Unsigned (Ins->NumDpts); + HTM_Unsigned (Dpt_GetNumDptsInIns (Ins->InsCod)); HTM_TD_End (); /* Number of users in courses of this institution */ @@ -698,7 +698,7 @@ void Ins_GetListInstitutions (long CtyCod,Ins_GetExtraData_t GetExtraData) switch (GetExtraData) { case Ins_GET_BASIC_DATA: - Ins->Ctrs.Num = Ins->NumDegs = Ins->NumCrss = Ins->NumDpts = 0; + Ins->Ctrs.Num = Ins->NumDegs = Ins->NumCrss = 0; break; case Ins_GET_EXTRA_DATA: /* Get number of centres in this institution */ @@ -709,9 +709,6 @@ void Ins_GetListInstitutions (long CtyCod,Ins_GetExtraData_t GetExtraData) /* Get number of degrees in this institution */ Ins->NumCrss = Crs_GetNumCrssInIns (Ins->InsCod); - - /* Get number of departments in this institution */ - Ins->NumDpts = Dpt_GetNumDptsInIns (Ins->InsCod); break; } } @@ -759,7 +756,7 @@ bool Ins_GetDataOfInstitutionByCod (struct Instit *Ins, Ins->ShrtName[0] = Ins->FullName[0] = Ins->WWW[0] = '\0'; - Ins->Ctrs.Num = Ins->NumDegs = Ins->NumCrss = Ins->NumDpts = 0; + Ins->Ctrs.Num = Ins->NumDegs = Ins->NumCrss = 0; /***** Check if institution code is correct *****/ if (Ins->InsCod > 0) @@ -801,9 +798,6 @@ bool Ins_GetDataOfInstitutionByCod (struct Instit *Ins, /* Get number of centres in this institution */ Ins->Ctrs.Num = Ctr_GetNumCtrsInIns (Ins->InsCod); - /* Get number of departments in this institution */ - Ins->NumDpts = Dpt_GetNumDptsInIns (Ins->InsCod); - /* Get number of degrees in this institution */ Ins->NumDegs = Deg_GetNumDegsInIns (Ins->InsCod); } @@ -1359,6 +1353,7 @@ void Ins_RemoveInstitution (void) /***** Flush caches *****/ Ins_FlushCacheShortNameOfInstitution (); Ins_FlushCacheFullNameAndCtyOfInstitution (); + Dpt_FlushCacheNumDptsInIns (); Usr_FlushCacheNumUsrsWhoClaimToBelongToIns (); Usr_FlushCacheNumUsrsInCrssOfIns (); @@ -2039,7 +2034,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->NumDpts = 0; Ins_EditingIns->NumDegs = 0; } diff --git a/swad_institution.h b/swad_institution.h index 7eaccc15..5eb82ffe 100644 --- a/swad_institution.h +++ b/swad_institution.h @@ -73,7 +73,6 @@ struct Instit } Ctrs; unsigned NumDegs; unsigned NumCrss; - unsigned NumDpts; }; #define Ins_NUM_ORDERS 2