diff --git a/swad_changelog.h b/swad_changelog.h index 92581463..f55ca44d 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.20 (2020-01-07)" +#define Log_PLATFORM_VERSION "SWAD 19.112.21 (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.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) Version 19.112.18:Jan 07, 2020 Optimization in number of users in a country. (278668 lines) diff --git a/swad_country.c b/swad_country.c index b03765c8..39b1f1e3 100644 --- a/swad_country.c +++ b/swad_country.c @@ -428,7 +428,7 @@ static void Cty_ListOneCountryForSeeing (struct Country *Cty,unsigned NumCty) HTM_TD_End (); HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor); - HTM_Unsigned (Cty->NumDegs); + HTM_Unsigned (Deg_GetNumDegsInCty (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 = Cty->NumDegs = 0; + Cty->Inss.Num = Cty->NumCtrs = 0; /* Get the name of the country in current language */ Str_Copy (Cty->Name[Gbl.Prefs.Language],row[2], @@ -871,9 +871,6 @@ void Cty_GetListCountries (Cty_GetExtraData_t GetExtraData) /* Get number of centres in this country */ Cty->NumCtrs = Ctr_GetNumCtrsInCty (Cty->CtyCod); - - /* Get number of degrees in this country */ - Cty->NumDegs = Deg_GetNumDegsInCty (Cty->CtyCod); break; } } @@ -1001,7 +998,7 @@ bool Cty_GetDataOfCountryByCod (struct Country *Cty,Cty_GetExtraData_t GetExtraD Cty->WWW[Lan][0] = '\0'; } Cty->NumUsrsWhoClaimToBelongToCty.Valid = false; - Cty->Inss.Num = Cty->NumCtrs = Cty->NumDegs = 0; + Cty->Inss.Num = Cty->NumCtrs = 0; /***** Check if country code is correct *****/ if (Cty->CtyCod == 0) @@ -1376,6 +1373,7 @@ void Cty_RemoveCountry (void) /***** Flush cache *****/ Cty_FlushCacheCountryName (); Ins_FlushCacheNumInssInCty (); + Deg_FlushCacheNumDegsInCty (); Crs_FlushCacheNumCrssInCty (); Usr_FlushCacheNumUsrsWhoClaimToBelongToCty (); @@ -2080,7 +2078,6 @@ static void Cty_EditingCountryConstructor (void) Cty_EditingCty->Inss.Lst = NULL; Cty_EditingCty->Inss.SelectedOrder = Ins_ORDER_DEFAULT; Cty_EditingCty->NumCtrs = 0; - Cty_EditingCty->NumDegs = 0; Cty_EditingCty->NumUsrsWhoClaimToBelongToCty.Valid = false; } diff --git a/swad_country.h b/swad_country.h index d9f35137..33d15e54 100644 --- a/swad_country.h +++ b/swad_country.h @@ -58,8 +58,6 @@ struct Country Ins_Order_t SelectedOrder; } Inss; unsigned NumCtrs; - unsigned NumDegs; - // unsigned NumCrss; struct { bool Valid; diff --git a/swad_degree.c b/swad_degree.c index c2bb7e89..4059c66b 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -1860,16 +1860,32 @@ unsigned Deg_GetNumDegsTotal (void) /********************* Get number of degrees in a country ********************/ /*****************************************************************************/ -unsigned Deg_GetNumDegsInCty (long InsCod) +void Deg_FlushCacheNumDegsInCty (void) { - /***** Get number of degrees in a country from database *****/ - return + Gbl.Cache.NumDegsInCty.CtyCod = -1L; + Gbl.Cache.NumDegsInCty.NumDegs = 0; + } + +unsigned Deg_GetNumDegsInCty (long CtyCod) + { + /***** 1. Fast check: Trivial case *****/ + if (CtyCod <= 0) + return 0; + + /***** 2. Fast check: If cached... *****/ + if (CtyCod == Gbl.Cache.NumDegsInCty.CtyCod) + return Gbl.Cache.NumDegsInCty.NumDegs; + + /***** 3. Slow: number of degrees in a country from database *****/ + Gbl.Cache.NumDegsInCty.CtyCod = CtyCod; + Gbl.Cache.NumDegsInCty.NumDegs = (unsigned) DB_QueryCOUNT ("can not get the number of degrees in a country", "SELECT COUNT(*) FROM institutions,centres,degrees" " WHERE institutions.CtyCod=%ld" " AND institutions.InsCod=centres.InsCod" " AND centres.CtrCod=degrees.CtrCod", - InsCod); + CtyCod); + return Gbl.Cache.NumDegsInCty.NumDegs; } /*****************************************************************************/ diff --git a/swad_degree.h b/swad_degree.h index 8faa88d6..e1f4edcc 100644 --- a/swad_degree.h +++ b/swad_degree.h @@ -140,7 +140,8 @@ void Deg_ReceiveLogo (void); void Deg_RemoveLogo (void); unsigned Deg_GetNumDegsTotal (void); -unsigned Deg_GetNumDegsInCty (long InsCod); +void Deg_FlushCacheNumDegsInCty (void); +unsigned Deg_GetNumDegsInCty (long CtyCod); void Deg_FlushCacheNumDegsInIns (void); unsigned Deg_GetNumDegsInIns (long InsCod); void Deg_FlushCacheNumDegsInCtr (void); diff --git a/swad_global.c b/swad_global.c index 6d0a1d27..e1353ccc 100644 --- a/swad_global.c +++ b/swad_global.c @@ -408,6 +408,7 @@ void Gbl_InitializeGlobals (void) Ins_FlushCacheFullNameAndCtyOfInstitution (); Ins_FlushCacheNumInssInCty (); + Deg_FlushCacheNumDegsInCty (); Crs_FlushCacheNumCrssInCty (); Dpt_FlushCacheNumDptsInIns (); diff --git a/swad_global.h b/swad_global.h index 523be7d3..8c8cac34 100644 --- a/swad_global.h +++ b/swad_global.h @@ -788,6 +788,11 @@ struct Globals long InsCod; unsigned NumCtrs; } NumCtrsInIns; + struct + { + long CtyCod; + unsigned NumDegs; + } NumDegsInCty; struct { long InsCod;