Version19.112.17

This commit is contained in:
Antonio Cañas Vargas 2020-01-07 00:42:24 +01:00
parent c1c5b80044
commit 6d0f193fd7
6 changed files with 44 additions and 20 deletions

View File

@ -492,7 +492,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - *
En OpenSWAD: En OpenSWAD:
ps2pdf source.ps destination.pdf ps2pdf source.ps destination.pdf
*/ */
#define Log_PLATFORM_VERSION "SWAD 19.112.16 (2020-01-06)" #define Log_PLATFORM_VERSION "SWAD 19.112.17 (2020-01-07)"
#define CSS_FILE "swad19.112.css" #define CSS_FILE "swad19.112.css"
#define JS_FILE "swad19.91.1.js" #define JS_FILE "swad19.91.1.js"
/* /*
@ -501,9 +501,9 @@ ps2pdf source.ps destination.pdf
// TODO: No se puede entrar con DNI '1' suponiendo que no tenga password ¿por qué? // TODO: No se puede entrar con DNI '1' suponiendo que no tenga password ¿por qué?
// TODO: Mapas más estrechos en móvil // TODO: Mapas más estrechos en móvil
// TODO: Quitar todos los EXTRA_DATA. // TODO: Quitar todos los EXTRA_DATA.
Optimize Ins_GetNumInssInCty
Version 19.112.16:Jan 06, 2020 Optimization in number of centres in an institution. (? lines) Version 19.112.17:Jan 07, 2020 Optimization in number of institutions in a country. (278600 lines)
Version 19.112.16:Jan 07, 2020 Optimization in number of centres in an institution. (278576 lines)
Version 19.112.15:Jan 06, 2020 Optimization in number of degrees in an institution. (278567 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.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.13:Jan 06, 2020 Optimization in number of departments in an institution. (278535 lines)

View File

@ -421,7 +421,7 @@ static void Cty_ListOneCountryForSeeing (struct Country *Cty,unsigned NumCty)
HTM_TD_End (); HTM_TD_End ();
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor); HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
HTM_Unsigned (Cty->Inss.Num); HTM_Unsigned (Ins_GetNumInssInCty (Cty->CtyCod));
HTM_TD_End (); HTM_TD_End ();
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor); HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
@ -880,9 +880,6 @@ void Cty_GetListCountries (Cty_GetExtraData_t GetExtraData)
&Cty->NumUsrsWhoClaimToBelongToCty) != 1) &Cty->NumUsrsWhoClaimToBelongToCty) != 1)
Cty->NumUsrsWhoClaimToBelongToCty = 0; Cty->NumUsrsWhoClaimToBelongToCty = 0;
/* Get number of institutions in this country */
Cty->Inss.Num = Ins_GetNumInssInCty (Cty->CtyCod);
/* Get number of centres in this country */ /* Get number of centres in this country */
Cty->NumCtrs = Ctr_GetNumCtrsInCty (Cty->CtyCod); Cty->NumCtrs = Ctr_GetNumCtrsInCty (Cty->CtyCod);
@ -1140,9 +1137,6 @@ bool Cty_GetDataOfCountryByCod (struct Country *Cty,Cty_GetExtraData_t GetExtraD
/* Get number of user in courses of this institution */ /* Get number of user in courses of this institution */
Cty->NumUsrs = Usr_GetNumUsrsInCrssOfCty (Rol_UNK,Cty->CtyCod); // Here Rol_UNK means "all users" Cty->NumUsrs = Usr_GetNumUsrsInCrssOfCty (Rol_UNK,Cty->CtyCod); // Here Rol_UNK means "all users"
/* Get number of institutions in this country */
Cty->Inss.Num = Ins_GetNumInssInCty (Cty->CtyCod);
break; break;
} }
} }
@ -1234,6 +1228,7 @@ static void Cty_ListCountriesForEdition (void)
extern const char *Txt_STR_LANG_NAME[1 + Lan_NUM_LANGUAGES]; extern const char *Txt_STR_LANG_NAME[1 + Lan_NUM_LANGUAGES];
unsigned NumCty; unsigned NumCty;
struct Country *Cty; struct Country *Cty;
unsigned NumInssInCty;
Lan_Language_t Lan; Lan_Language_t Lan;
/***** Write heading *****/ /***** Write heading *****/
@ -1246,14 +1241,16 @@ static void Cty_ListCountriesForEdition (void)
NumCty++) NumCty++)
{ {
Cty = &Gbl.Hierarchy.Sys.Ctys.Lst[NumCty]; Cty = &Gbl.Hierarchy.Sys.Ctys.Lst[NumCty];
NumInssInCty = Ins_GetNumInssInCty (Cty->CtyCod);
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
/* Put icon to remove country */ /* Put icon to remove country */
HTM_TD_Begin ("rowspan=\"%u\" class=\"BT\"",1 + Lan_NUM_LANGUAGES); HTM_TD_Begin ("rowspan=\"%u\" class=\"BT\"",1 + Lan_NUM_LANGUAGES);
if (Cty->Inss.Num || if (NumInssInCty || // Country has institutions
Cty->NumUsrsWhoClaimToBelongToCty || Cty->NumUsrsWhoClaimToBelongToCty ||
Cty->NumUsrs) // Country has institutions or users ==> deletion forbidden Cty->NumUsrs) // Country has users
// Deletion forbidden
Ico_PutIconRemovalNotAllowed (); Ico_PutIconRemovalNotAllowed ();
else else
{ {
@ -1283,7 +1280,7 @@ static void Cty_ListCountriesForEdition (void)
/* Number of institutions */ /* Number of institutions */
HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES); HTM_TD_Begin ("rowspan=\"%u\" class=\"DAT RT\"",1 + Lan_NUM_LANGUAGES);
HTM_Unsigned (Cty->Inss.Num); HTM_Unsigned (NumInssInCty);
HTM_TD_End (); HTM_TD_End ();
HTM_TR_End (); HTM_TR_End ();
@ -1386,9 +1383,11 @@ void Cty_RemoveCountry (void)
Cty_GetDataOfCountryByCod (Cty_EditingCty,Cty_GET_EXTRA_DATA); Cty_GetDataOfCountryByCod (Cty_EditingCty,Cty_GET_EXTRA_DATA);
/***** Check if this country has users *****/ /***** Check if this country has users *****/
if (Cty_EditingCty->Inss.Num || if (Ins_GetNumInssInCty (Cty_EditingCty->CtyCod)) // Country has institutions ==> don't remove
Cty_EditingCty->NumUsrsWhoClaimToBelongToCty || Ale_CreateAlert (Ale_WARNING,NULL,
Cty_EditingCty->NumUsrs) // Country has institutions or users ==> don't remove Txt_You_can_not_remove_a_country_with_institutions_or_users);
else if (Cty_EditingCty->NumUsrsWhoClaimToBelongToCty ||
Cty_EditingCty->NumUsrs) // Country has users ==> don't remove
Ale_CreateAlert (Ale_WARNING,NULL, Ale_CreateAlert (Ale_WARNING,NULL,
Txt_You_can_not_remove_a_country_with_institutions_or_users); Txt_You_can_not_remove_a_country_with_institutions_or_users);
else // Country has no users ==> remove it else // Country has no users ==> remove it
@ -1403,6 +1402,7 @@ void Cty_RemoveCountry (void)
/***** Flush cache *****/ /***** Flush cache *****/
Cty_FlushCacheCountryName (); Cty_FlushCacheCountryName ();
Ins_FlushCacheNumInssInCty ();
/***** Write message to show the change made *****/ /***** Write message to show the change made *****/
Ale_CreateAlert (Ale_SUCCESS,NULL, Ale_CreateAlert (Ale_SUCCESS,NULL,

View File

@ -406,6 +406,7 @@ void Gbl_InitializeGlobals (void)
Cty_FlushCacheCountryName (); Cty_FlushCacheCountryName ();
Ins_FlushCacheShortNameOfInstitution (); Ins_FlushCacheShortNameOfInstitution ();
Ins_FlushCacheFullNameAndCtyOfInstitution (); Ins_FlushCacheFullNameAndCtyOfInstitution ();
Ins_FlushCacheNumInssInCty ();
Dpt_FlushCacheNumDptsInIns (); Dpt_FlushCacheNumDptsInIns ();
Ctr_FlushCacheNumCtrsInIns (); Ctr_FlushCacheNumCtrsInIns ();
Deg_FlushCacheNumDegsInIns (); Deg_FlushCacheNumDegsInIns ();

View File

@ -777,6 +777,12 @@ struct Globals
long InsCod; long InsCod;
unsigned NumDpts; unsigned NumDpts;
} NumDptsInIns; } NumDptsInIns;
struct
{
bool Valid;
long CtyCod;
unsigned NumInss;
} NumInssInCty;
struct struct
{ {
long InsCod; long InsCod;

View File

@ -321,7 +321,7 @@ static void Ins_ListInstitutions (void)
{ {
Frm_StartForm (ActEdiIns); Frm_StartForm (ActEdiIns);
Btn_PutConfirmButton (Gbl.Hierarchy.Cty.Inss.Num ? Txt_Create_another_institution : Btn_PutConfirmButton (Gbl.Hierarchy.Cty.Inss.Num ? Txt_Create_another_institution :
Txt_Create_institution); Txt_Create_institution);
Frm_EndForm (); Frm_EndForm ();
} }
@ -696,7 +696,10 @@ void Ins_GetListInstitutions (long CtyCod)
} }
} }
else else
{
Gbl.Hierarchy.Cty.Inss.Num = 0; Gbl.Hierarchy.Cty.Inss.Num = 0;
Gbl.Hierarchy.Cty.Inss.Lst = NULL;
}
/***** Free structure that stores the query result *****/ /***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res); DB_FreeMySQLResult (&mysql_res);
@ -925,8 +928,8 @@ void Ins_FreeListInstitutions (void)
{ {
/***** Free memory used by the list of institutions *****/ /***** Free memory used by the list of institutions *****/
free (Gbl.Hierarchy.Cty.Inss.Lst); free (Gbl.Hierarchy.Cty.Inss.Lst);
Gbl.Hierarchy.Cty.Inss.Lst = NULL;
Gbl.Hierarchy.Cty.Inss.Num = 0; Gbl.Hierarchy.Cty.Inss.Num = 0;
Gbl.Hierarchy.Cty.Inss.Lst = NULL;
} }
} }
@ -1860,15 +1863,28 @@ unsigned Ins_GetNumInssTotal (void)
/**************** Get number of institutions in a country ********************/ /**************** Get number of institutions in a country ********************/
/*****************************************************************************/ /*****************************************************************************/
void Ins_FlushCacheNumInssInCty (void)
{
Gbl.Cache.NumInssInCty.Valid = false;
}
unsigned Ins_GetNumInssInCty (long CtyCod) unsigned Ins_GetNumInssInCty (long CtyCod)
{ {
/***** Get number of degrees of a place from database *****/ /***** 1. Fast check: If cached... *****/
return if (Gbl.Cache.NumInssInCty.Valid &&
CtyCod == Gbl.Cache.NumInssInCty.CtyCod)
return Gbl.Cache.NumInssInCty.NumInss;
/***** 2. Slow: number of institutions in a country from database *****/
Gbl.Cache.NumInssInCty.CtyCod = CtyCod;
Gbl.Cache.NumInssInCty.NumInss =
(unsigned) DB_QueryCOUNT ("can not get the number of institutions" (unsigned) DB_QueryCOUNT ("can not get the number of institutions"
" in a country", " in a country",
"SELECT COUNT(*) FROM institutions" "SELECT COUNT(*) FROM institutions"
" WHERE CtyCod=%ld", " WHERE CtyCod=%ld",
CtyCod); CtyCod);
Gbl.Cache.NumInssInCty.Valid = true;
return Gbl.Cache.NumInssInCty.NumInss;
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -129,6 +129,7 @@ void Ins_RecFormReqIns (void);
void Ins_RecFormNewIns (void); void Ins_RecFormNewIns (void);
unsigned Ins_GetNumInssTotal (void); unsigned Ins_GetNumInssTotal (void);
void Ins_FlushCacheNumInssInCty (void);
unsigned Ins_GetNumInssInCty (long CtyCod); unsigned Ins_GetNumInssInCty (long CtyCod);
unsigned Ins_GetNumInssWithCtrs (const char *SubQuery); unsigned Ins_GetNumInssWithCtrs (const char *SubQuery);
unsigned Ins_GetNumInssWithDegs (const char *SubQuery); unsigned Ins_GetNumInssWithDegs (const char *SubQuery);