From a8e670490f4278d4a817a0ed4bc219f2e729ff57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Tue, 7 Jan 2020 16:37:46 +0100 Subject: [PATCH] Version19.112.22 --- swad_centre.c | 20 ++++++++++++++++++-- swad_centre.h | 1 + swad_changelog.h | 3 ++- swad_country.c | 13 ++++++------- swad_country.h | 1 - swad_global.c | 1 + swad_global.h | 5 +++++ 7 files changed, 33 insertions(+), 11 deletions(-) diff --git a/swad_centre.c b/swad_centre.c index dbb35559..307608a6 100644 --- a/swad_centre.c +++ b/swad_centre.c @@ -1828,15 +1828,31 @@ unsigned Ctr_GetNumCtrsTotal (void) /******************* Get number of centres in a country **********************/ /*****************************************************************************/ +void Ctr_FlushCacheNumCtrsInCty (void) + { + Gbl.Cache.NumCtrsInCty.CtyCod = -1L; + Gbl.Cache.NumCtrsInCty.NumCtrs = 0; + } + unsigned Ctr_GetNumCtrsInCty (long CtyCod) { - /***** Get number of centres of a country from database *****/ - return + /***** 1. Fast check: Trivial case *****/ + if (CtyCod <= 0) + return 0; + + /***** 2. Fast check: If cached... *****/ + if (CtyCod == Gbl.Cache.NumCtrsInCty.CtyCod) + return Gbl.Cache.NumCtrsInCty.NumCtrs; + + /***** 3. Slow: number of centres in a country from database *****/ + Gbl.Cache.NumCtrsInCty.CtyCod = CtyCod; + Gbl.Cache.NumCtrsInCty.NumCtrs = (unsigned) DB_QueryCOUNT ("can not get number of centres in a country", "SELECT COUNT(*) FROM institutions,centres" " WHERE institutions.CtyCod=%ld" " AND institutions.InsCod=centres.InsCod", CtyCod); + return Gbl.Cache.NumCtrsInCty.NumCtrs; } /*****************************************************************************/ diff --git a/swad_centre.h b/swad_centre.h index ff8b0753..eeb990c0 100644 --- a/swad_centre.h +++ b/swad_centre.h @@ -121,6 +121,7 @@ void Ctr_RecFormReqCtr (void); void Ctr_RecFormNewCtr (void); unsigned Ctr_GetNumCtrsTotal (void); +void Ctr_FlushCacheNumCtrsInCty (void); unsigned Ctr_GetNumCtrsInCty (long CtyCod); void Ctr_FlushCacheNumCtrsInIns (void); unsigned Ctr_GetNumCtrsInIns (long InsCod); diff --git a/swad_changelog.h b/swad_changelog.h index f55ca44d..db5ea2a4 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.21 (2020-01-07)" +#define Log_PLATFORM_VERSION "SWAD 19.112.22 (2020-01-07)" #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.22:Jan 07, 2020 Optimization in number of centres in a country. (278761 lines) Version 19.112.21:Jan 07, 2020 Optimization in number of degrees in a country. (278741 lines) Version 19.112.20:Jan 07, 2020 Optimization in number of courses in a country. (278724 lines) Version 19.112.19:Jan 07, 2020 Optimization in number of users in a country. (278675 lines) diff --git a/swad_country.c b/swad_country.c index 39b1f1e3..1c3282fe 100644 --- a/swad_country.c +++ b/swad_country.c @@ -424,7 +424,7 @@ static void Cty_ListOneCountryForSeeing (struct Country *Cty,unsigned NumCty) HTM_TD_End (); HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor); - HTM_Unsigned (Cty->NumCtrs); + HTM_Unsigned (Ctr_GetNumCtrsInCty (Cty->CtyCod)); HTM_TD_End (); HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor); @@ -844,7 +844,7 @@ void Cty_GetListCountries (Cty_GetExtraData_t GetExtraData) Cty->WWW[Lan][0] = '\0'; } Cty->NumUsrsWhoClaimToBelongToCty.Valid = false; - Cty->Inss.Num = Cty->NumCtrs = 0; + Cty->Inss.Num = 0; /* Get the name of the country in current language */ Str_Copy (Cty->Name[Gbl.Prefs.Language],row[2], @@ -868,9 +868,6 @@ void Cty_GetListCountries (Cty_GetExtraData_t GetExtraData) Cty->NumUsrsWhoClaimToBelongToCty.Valid = true; else Cty->NumUsrsWhoClaimToBelongToCty.Valid = false; - - /* Get number of centres in this country */ - Cty->NumCtrs = Ctr_GetNumCtrsInCty (Cty->CtyCod); break; } } @@ -997,8 +994,10 @@ bool Cty_GetDataOfCountryByCod (struct Country *Cty,Cty_GetExtraData_t GetExtraD Cty->Name[Lan][0] = '\0'; Cty->WWW[Lan][0] = '\0'; } + Cty->Inss.Num = 0; + Cty->Inss.Lst = NULL; + Cty->Inss.SelectedOrder = Ins_ORDER_DEFAULT; Cty->NumUsrsWhoClaimToBelongToCty.Valid = false; - Cty->Inss.Num = Cty->NumCtrs = 0; /***** Check if country code is correct *****/ if (Cty->CtyCod == 0) @@ -1373,6 +1372,7 @@ void Cty_RemoveCountry (void) /***** Flush cache *****/ Cty_FlushCacheCountryName (); Ins_FlushCacheNumInssInCty (); + Ctr_FlushCacheNumCtrsInCty (); Deg_FlushCacheNumDegsInCty (); Crs_FlushCacheNumCrssInCty (); Usr_FlushCacheNumUsrsWhoClaimToBelongToCty (); @@ -2077,7 +2077,6 @@ static void Cty_EditingCountryConstructor (void) Cty_EditingCty->Inss.Num = 0; Cty_EditingCty->Inss.Lst = NULL; Cty_EditingCty->Inss.SelectedOrder = Ins_ORDER_DEFAULT; - Cty_EditingCty->NumCtrs = 0; Cty_EditingCty->NumUsrsWhoClaimToBelongToCty.Valid = false; } diff --git a/swad_country.h b/swad_country.h index 33d15e54..9569b2e2 100644 --- a/swad_country.h +++ b/swad_country.h @@ -57,7 +57,6 @@ struct Country struct Instit *Lst; // List of institutions in this country Ins_Order_t SelectedOrder; } Inss; - unsigned NumCtrs; struct { bool Valid; diff --git a/swad_global.c b/swad_global.c index e1353ccc..b9d237d8 100644 --- a/swad_global.c +++ b/swad_global.c @@ -408,6 +408,7 @@ void Gbl_InitializeGlobals (void) Ins_FlushCacheFullNameAndCtyOfInstitution (); Ins_FlushCacheNumInssInCty (); + Ctr_FlushCacheNumCtrsInCty (); Deg_FlushCacheNumDegsInCty (); Crs_FlushCacheNumCrssInCty (); diff --git a/swad_global.h b/swad_global.h index 8c8cac34..7676e807 100644 --- a/swad_global.h +++ b/swad_global.h @@ -783,6 +783,11 @@ struct Globals long CtyCod; unsigned NumInss; } NumInssInCty; + struct + { + long CtyCod; + unsigned NumCtrs; + } NumCtrsInCty; struct { long InsCod;