mirror of https://github.com/acanas/swad-core.git
Version19.112.20
This commit is contained in:
parent
3595d1bffc
commit
d91f19a3fb
|
@ -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.19 (2020-01-07)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 19.112.20 (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.20:Jan 07, 2020 Optimization in number of users in a country. (? 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)
|
||||
Version 19.112.17:Jan 07, 2020 Optimization in number of institutions in a country. (278600 lines)
|
||||
|
|
|
@ -436,7 +436,7 @@ static void Cty_ListOneCountryForSeeing (struct Country *Cty,unsigned NumCty)
|
|||
HTM_TD_End ();
|
||||
|
||||
HTM_TD_Begin ("class=\"DAT RM %s\"",BgColor);
|
||||
HTM_Unsigned (Cty->NumUsrs);
|
||||
HTM_Unsigned (Usr_GetNumUsrsInCrssOfCty (Rol_UNK,Cty->CtyCod)); // Here Rol_UNK means "all users"
|
||||
HTM_TD_End ();
|
||||
|
||||
HTM_TR_End ();
|
||||
|
@ -845,7 +845,6 @@ void Cty_GetListCountries (Cty_GetExtraData_t GetExtraData)
|
|||
}
|
||||
Cty->NumUsrsWhoClaimToBelongToCty.Valid = false;
|
||||
Cty->Inss.Num = Cty->NumCtrs = Cty->NumDegs = Cty->NumCrss = 0;
|
||||
Cty->NumUsrs = 0;
|
||||
|
||||
/* Get the name of the country in current language */
|
||||
Str_Copy (Cty->Name[Gbl.Prefs.Language],row[2],
|
||||
|
@ -878,9 +877,6 @@ void Cty_GetListCountries (Cty_GetExtraData_t GetExtraData)
|
|||
|
||||
/* Get number of courses in this country */
|
||||
Cty->NumCrss = Crs_GetNumCrssInCty (Cty->CtyCod);
|
||||
|
||||
/* Get number of users in courses of this country */
|
||||
Cty->NumUsrs = Usr_GetNumUsrsInCrssOfCty (Rol_UNK,Cty->CtyCod); // Here Rol_UNK means "all users"
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1009,7 +1005,6 @@ bool Cty_GetDataOfCountryByCod (struct Country *Cty,Cty_GetExtraData_t GetExtraD
|
|||
}
|
||||
Cty->NumUsrsWhoClaimToBelongToCty.Valid = false;
|
||||
Cty->Inss.Num = Cty->NumCtrs = Cty->NumDegs = Cty->NumCrss = 0;
|
||||
Cty->NumUsrs = 0;
|
||||
|
||||
/***** Check if country code is correct *****/
|
||||
if (Cty->CtyCod == 0)
|
||||
|
@ -1110,10 +1105,6 @@ bool Cty_GetDataOfCountryByCod (struct Country *Cty,Cty_GetExtraData_t GetExtraD
|
|||
Str_Copy (Cty->WWW[Lan],row[Lan_NUM_LANGUAGES + Lan],
|
||||
Cns_MAX_BYTES_WWW);
|
||||
}
|
||||
|
||||
/* Get number of user in courses of this institution */
|
||||
Cty->NumUsrs = Usr_GetNumUsrsInCrssOfCty (Rol_UNK,Cty->CtyCod); // Here Rol_UNK means "all users"
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1224,13 +1215,16 @@ static void Cty_ListCountriesForEdition (void)
|
|||
|
||||
/* Put icon to remove country */
|
||||
HTM_TD_Begin ("rowspan=\"%u\" class=\"BT\"",1 + Lan_NUM_LANGUAGES);
|
||||
if (NumInssInCty || // Country has institutions
|
||||
Cty->NumUsrs) // Country has users
|
||||
if (NumInssInCty) // Country has institutions
|
||||
// Deletion forbidden
|
||||
Ico_PutIconRemovalNotAllowed ();
|
||||
else if (Usr_GetNumUsrsWhoClaimToBelongToCty (Cty)) // Country has users
|
||||
// Deletion forbidden
|
||||
Ico_PutIconRemovalNotAllowed ();
|
||||
else if (Usr_GetNumUsrsInCrssOfCty (Rol_UNK, // Here Rol_UNK means "all users"
|
||||
Cty->CtyCod)) // Country has users
|
||||
// Deletion forbidden
|
||||
Ico_PutIconRemovalNotAllowed ();
|
||||
else
|
||||
{
|
||||
Frm_StartForm (ActRemCty);
|
||||
|
@ -1365,10 +1359,11 @@ void Cty_RemoveCountry (void)
|
|||
if (Ins_GetNumInssInCty (Cty_EditingCty->CtyCod)) // Country has institutions ==> don't remove
|
||||
Ale_CreateAlert (Ale_WARNING,NULL,
|
||||
Txt_You_can_not_remove_a_country_with_institutions_or_users);
|
||||
else if (Cty_EditingCty->NumUsrs) // Country has users ==> don't remove
|
||||
else if (Usr_GetNumUsrsWhoClaimToBelongToCty (Cty_EditingCty)) // Country has users ==> don't remove
|
||||
Ale_CreateAlert (Ale_WARNING,NULL,
|
||||
Txt_You_can_not_remove_a_country_with_institutions_or_users);
|
||||
else if (Usr_GetNumUsrsWhoClaimToBelongToCty (Cty_EditingCty)) // Country has users ==> don't remove
|
||||
else if (Usr_GetNumUsrsInCrssOfCty (Rol_UNK, // Here Rol_UNK means "all users"
|
||||
Cty_EditingCty->CtyCod)) // Country has users
|
||||
Ale_CreateAlert (Ale_WARNING,NULL,
|
||||
Txt_You_can_not_remove_a_country_with_institutions_or_users);
|
||||
else // Country has no users ==> remove it
|
||||
|
@ -2089,7 +2084,6 @@ static void Cty_EditingCountryConstructor (void)
|
|||
Cty_EditingCty->NumCtrs = 0;
|
||||
Cty_EditingCty->NumDegs = 0;
|
||||
Cty_EditingCty->NumCrss = 0;
|
||||
Cty_EditingCty->NumUsrs = 0;
|
||||
Cty_EditingCty->NumUsrsWhoClaimToBelongToCty.Valid = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,6 @@ struct Country
|
|||
unsigned NumCtrs;
|
||||
unsigned NumDegs;
|
||||
unsigned NumCrss;
|
||||
unsigned NumUsrs; // Number of users in courses of the institution
|
||||
struct
|
||||
{
|
||||
bool Valid;
|
||||
|
|
|
@ -838,6 +838,11 @@ struct Globals
|
|||
long CtrCod;
|
||||
unsigned NumUsrs;
|
||||
} NumUsrsWhoClaimToBelongToCtr;
|
||||
struct
|
||||
{
|
||||
long CtyCod;
|
||||
unsigned NumUsrs;
|
||||
} NumUsrsInCrssOfCty[Rol_NUM_ROLES];
|
||||
struct
|
||||
{
|
||||
long InsCod;
|
||||
|
|
45
swad_user.c
45
swad_user.c
|
@ -4424,15 +4424,48 @@ unsigned Usr_GetNumUsrsInCrssOfIns (Rol_Role_t Role,long InsCod)
|
|||
/*****************************************************************************/
|
||||
/****** Count how many users with a role belong to courses of a country ******/
|
||||
/*****************************************************************************/
|
||||
// Here Rol_UNK means students or teachers
|
||||
// Here Rol_UNK means any user (students, non-editing teachers or teachers)
|
||||
|
||||
void Usr_FlushCacheNumUsrsInCrssOfCty (void)
|
||||
{
|
||||
Gbl.Cache.NumUsrsInCrssOfCty[Rol_UNK].CtyCod =
|
||||
Gbl.Cache.NumUsrsInCrssOfCty[Rol_STD].CtyCod =
|
||||
Gbl.Cache.NumUsrsInCrssOfCty[Rol_NET].CtyCod =
|
||||
Gbl.Cache.NumUsrsInCrssOfCty[Rol_TCH].CtyCod = -1L;
|
||||
|
||||
Gbl.Cache.NumUsrsInCrssOfCty[Rol_UNK].NumUsrs =
|
||||
Gbl.Cache.NumUsrsInCrssOfCty[Rol_STD].NumUsrs =
|
||||
Gbl.Cache.NumUsrsInCrssOfCty[Rol_NET].NumUsrs =
|
||||
Gbl.Cache.NumUsrsInCrssOfCty[Rol_TCH].NumUsrs = 0;
|
||||
}
|
||||
|
||||
unsigned Usr_GetNumUsrsInCrssOfCty (Rol_Role_t Role,long CtyCod)
|
||||
{
|
||||
unsigned NumUsrs;
|
||||
/***** 1. Fast check: Trivial case *****/
|
||||
if (CtyCod <= 0)
|
||||
return 0;
|
||||
|
||||
/***** Get the number of users in courses of a country from database ******/
|
||||
/***** 2. Fast check: Trivial case *****/
|
||||
switch (Role)
|
||||
{
|
||||
case Rol_UNK: // Here Rol_UNK means all
|
||||
case Rol_STD:
|
||||
case Rol_NET:
|
||||
case Rol_TCH:
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***** 3. Fast check: If cached... *****/
|
||||
if (CtyCod == Gbl.Cache.NumUsrsInCrssOfCty[Role].CtyCod)
|
||||
return Gbl.Cache.NumUsrsInCrssOfCty[Role].NumUsrs;
|
||||
|
||||
/***** 4. Slow: get number of users in courses of a country
|
||||
from database *****/
|
||||
Gbl.Cache.NumUsrsInCrssOfCty[Role].CtyCod = CtyCod;
|
||||
if (Role == Rol_UNK) // Any user
|
||||
NumUsrs =
|
||||
Gbl.Cache.NumUsrsInCrssOfCty[Rol_UNK].NumUsrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of users",
|
||||
"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
|
||||
" FROM institutions,centres,degrees,courses,crs_usr"
|
||||
|
@ -4445,7 +4478,7 @@ unsigned Usr_GetNumUsrsInCrssOfCty (Rol_Role_t Role,long CtyCod)
|
|||
else
|
||||
// This query is very slow.
|
||||
// It's a bad idea to get number of teachers or students for a big list of countries
|
||||
NumUsrs =
|
||||
Gbl.Cache.NumUsrsInCrssOfCty[Role].NumUsrs =
|
||||
(unsigned) DB_QueryCOUNT ("can not get number of users",
|
||||
"SELECT COUNT(DISTINCT crs_usr.UsrCod)"
|
||||
" FROM institutions,centres,degrees,courses,crs_usr"
|
||||
|
@ -4456,7 +4489,7 @@ unsigned Usr_GetNumUsrsInCrssOfCty (Rol_Role_t Role,long CtyCod)
|
|||
" AND courses.CrsCod=crs_usr.CrsCod"
|
||||
" AND crs_usr.Role=%u",
|
||||
CtyCod,(unsigned) Role);
|
||||
return NumUsrs;
|
||||
return Gbl.Cache.NumUsrsInCrssOfCty[Role].NumUsrs;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
Loading…
Reference in New Issue