Version19.112.12

This commit is contained in:
Antonio Cañas Vargas 2020-01-06 18:00:23 +01:00
parent 5274fa7943
commit e18455dd1f
7 changed files with 70 additions and 35 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.11 (2020-01-06)" #define Log_PLATFORM_VERSION "SWAD 19.112.12 (2020-01-06)"
#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"
/* /*
@ -502,6 +502,7 @@ ps2pdf source.ps destination.pdf
// 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.
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.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) Version 19.112.10:Jan 06, 2020 Optimization in number of users in courses of a degree. (278468 lines)
Version 19.112.9: Jan 05, 2020 Optimization in number of users in a course. (278419 lines) Version 19.112.9: Jan 05, 2020 Optimization in number of users in a course. (278419 lines)

View File

@ -414,6 +414,7 @@ void Gbl_InitializeGlobals (void)
Deg_FlushCacheNumDegsInCtr (); Deg_FlushCacheNumDegsInCtr ();
Crs_FlushCacheNumCrssInCtr (); Crs_FlushCacheNumCrssInCtr ();
Crs_FlushCacheNumCrssInDeg (); Crs_FlushCacheNumCrssInDeg ();
Usr_FlushCacheNumUsrsWhoClaimToBelongToIns ();
Usr_FlushCacheNumUsrsWhoClaimToBelongToCtr (); Usr_FlushCacheNumUsrsWhoClaimToBelongToCtr ();
Usr_FlushCacheNumUsrsInCrssOfIns (); Usr_FlushCacheNumUsrsInCrssOfIns ();
Usr_FlushCacheNumUsrsInCrssOfCtr (); Usr_FlushCacheNumUsrsInCrssOfCtr ();

View File

@ -787,6 +787,11 @@ struct Globals
long DegCod; long DegCod;
unsigned NumCrss; unsigned NumCrss;
} NumCrssInDeg; } NumCrssInDeg;
struct
{
long InsCod;
unsigned NumUsrs;
} NumUsrsWhoClaimToBelongToIns;
struct struct
{ {
long CtrCod; long CtrCod;

View File

@ -402,7 +402,7 @@ static void Ins_ListOneInstitutionForSeeing (struct Instit *Ins,unsigned NumIns)
/***** Stats *****/ /***** Stats *****/
/* Number of users who claim to belong to this institution */ /* Number of users who claim to belong to this institution */
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor); HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
HTM_Unsigned (Ins->NumUsrsWhoClaimToBelongToIns); HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToIns (Ins->InsCod));
HTM_TD_End (); HTM_TD_End ();
/* Number of centres in this institution */ /* Number of centres in this institution */
@ -593,11 +593,6 @@ static void Ins_PutIconToViewInstitutions (void)
void Ins_GetListInstitutions (long CtyCod,Ins_GetExtraData_t GetExtraData) void Ins_GetListInstitutions (long CtyCod,Ins_GetExtraData_t GetExtraData)
{ {
static const char *OrderBySubQuery[Ins_NUM_ORDERS] =
{
[Ins_ORDER_BY_INSTITUTION] = "FullName",
[Ins_ORDER_BY_NUM_USRS ] = "NumUsrs DESC,FullName",
};
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long NumRows = 0; // Initialized to avoid warning unsigned long NumRows = 0; // Initialized to avoid warning
@ -605,35 +600,51 @@ void Ins_GetListInstitutions (long CtyCod,Ins_GetExtraData_t GetExtraData)
struct Instit *Ins; struct Instit *Ins;
/***** Get institutions from database *****/ /***** Get institutions from database *****/
switch (GetExtraData) switch (Gbl.Hierarchy.Cty.Inss.SelectedOrder)
{ {
case Ins_GET_BASIC_DATA: case Ins_ORDER_BY_INSTITUTION:
NumRows = DB_QuerySELECT (&mysql_res,"can not get institutions", NumRows = DB_QuerySELECT (&mysql_res,"can not get institutions",
"SELECT InsCod,CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW" "SELECT InsCod," // row[0]
"CtyCod," // row[1]
"Status," // row[2]
"RequesterUsrCod," // row[3]
"ShortName," // row[4]
"FullName," // row[5]
"WWW" // row[6]
" FROM institutions" " FROM institutions"
" WHERE CtyCod=%ld" " WHERE CtyCod=%ld"
" ORDER BY FullName", " ORDER BY FullName",
CtyCod); CtyCod);
break; break;
case Ins_GET_EXTRA_DATA: case Ins_ORDER_BY_NUM_USRS:
NumRows = DB_QuerySELECT (&mysql_res,"can not get institutions", NumRows = DB_QuerySELECT (&mysql_res,"can not get institutions",
"(SELECT institutions.InsCod,institutions.CtyCod," "(SELECT institutions.InsCod," // row[0]
"institutions.Status,institutions.RequesterUsrCod," "institutions.CtyCod," // row[1]
"institutions.ShortName,institutions.FullName," "institutions.Status," // row[2]
"institutions.WWW,COUNT(*) AS NumUsrs" "institutions.RequesterUsrCod," // row[3]
"institutions.ShortName," // row[4]
"institutions.FullName," // row[5]
"institutions.WWW," // row[6]
"COUNT(*) AS NumUsrs" // row[7]
" FROM institutions,usr_data" " FROM institutions,usr_data"
" WHERE institutions.CtyCod=%ld" " WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=usr_data.InsCod" " AND institutions.InsCod=usr_data.InsCod"
" GROUP BY institutions.InsCod)" " GROUP BY institutions.InsCod)"
" UNION " " UNION "
"(SELECT InsCod,CtyCod,Status,RequesterUsrCod,ShortName,FullName,WWW,0 AS NumUsrs" "(SELECT InsCod," // row[0]
"CtyCod," // row[1]
"Status," // row[2]
"RequesterUsrCod," // row[3]
"ShortName," // row[4]
"FullName," // row[5]
"WWW," // row[6]
"0 AS NumUsrs" // row[7]
" FROM institutions" " FROM institutions"
" WHERE CtyCod=%ld" " WHERE CtyCod=%ld"
" AND InsCod NOT IN" " AND InsCod NOT IN"
" (SELECT DISTINCT InsCod FROM usr_data))" " (SELECT DISTINCT InsCod FROM usr_data))"
" ORDER BY %s", " ORDER BY NumUsrs DESC,FullName",
CtyCod,CtyCod, CtyCod,CtyCod);
OrderBySubQuery[Gbl.Hierarchy.Cty.Inss.SelectedOrder]);
break; break;
} }
@ -643,7 +654,8 @@ void Ins_GetListInstitutions (long CtyCod,Ins_GetExtraData_t GetExtraData)
Gbl.Hierarchy.Cty.Inss.Num = (unsigned) NumRows; Gbl.Hierarchy.Cty.Inss.Num = (unsigned) NumRows;
/***** Create list with institutions *****/ /***** Create list with institutions *****/
if ((Gbl.Hierarchy.Cty.Inss.Lst = (struct Instit *) calloc (NumRows,sizeof (struct Instit))) == NULL) if ((Gbl.Hierarchy.Cty.Inss.Lst = (struct Instit *)
calloc (NumRows,sizeof (struct Instit))) == NULL)
Lay_NotEnoughMemoryExit (); Lay_NotEnoughMemoryExit ();
/***** Get the institutions *****/ /***** Get the institutions *****/
@ -686,14 +698,9 @@ void Ins_GetListInstitutions (long CtyCod,Ins_GetExtraData_t GetExtraData)
switch (GetExtraData) switch (GetExtraData)
{ {
case Ins_GET_BASIC_DATA: case Ins_GET_BASIC_DATA:
Ins->NumUsrsWhoClaimToBelongToIns = 0;
Ins->Ctrs.Num = Ins->NumDegs = Ins->NumCrss = Ins->NumDpts = 0; Ins->Ctrs.Num = Ins->NumDegs = Ins->NumCrss = Ins->NumDpts = 0;
break; break;
case Ins_GET_EXTRA_DATA: case Ins_GET_EXTRA_DATA:
/* Get number of users who claim to belong to this institution (row[7]) */
if (sscanf (row[7],"%u",&Ins->NumUsrsWhoClaimToBelongToIns) != 1)
Ins->NumUsrsWhoClaimToBelongToIns = 0;
/* Get number of centres in this institution */ /* Get number of centres in this institution */
Ins->Ctrs.Num = Ctr_GetNumCtrsInIns (Ins->InsCod); Ins->Ctrs.Num = Ctr_GetNumCtrsInIns (Ins->InsCod);
@ -752,7 +759,6 @@ bool Ins_GetDataOfInstitutionByCod (struct Instit *Ins,
Ins->ShrtName[0] = Ins->ShrtName[0] =
Ins->FullName[0] = Ins->FullName[0] =
Ins->WWW[0] = '\0'; Ins->WWW[0] = '\0';
Ins->NumUsrsWhoClaimToBelongToIns = 0;
Ins->Ctrs.Num = Ins->NumDegs = Ins->NumCrss = Ins->NumDpts = 0; Ins->Ctrs.Num = Ins->NumDegs = Ins->NumCrss = Ins->NumDpts = 0;
/***** Check if institution code is correct *****/ /***** Check if institution code is correct *****/
@ -1034,6 +1040,7 @@ static void Ins_ListInstitutionsForEdition (void)
struct UsrData UsrDat; struct UsrData UsrDat;
bool ICanEdit; bool ICanEdit;
unsigned NumUsrsInCrssOfIns; unsigned NumUsrsInCrssOfIns;
unsigned NumUsrsWhoClaimToBelongToIns;
Ins_StatusTxt_t StatusTxt; Ins_StatusTxt_t StatusTxt;
unsigned StatusUnsigned; unsigned StatusUnsigned;
@ -1053,6 +1060,7 @@ static void Ins_ListInstitutionsForEdition (void)
ICanEdit = Ins_CheckIfICanEdit (Ins); ICanEdit = Ins_CheckIfICanEdit (Ins);
NumUsrsInCrssOfIns = Usr_GetNumUsrsInCrssOfIns (Rol_UNK,Ins->InsCod); // Here Rol_UNK means "all users" NumUsrsInCrssOfIns = Usr_GetNumUsrsInCrssOfIns (Rol_UNK,Ins->InsCod); // Here Rol_UNK means "all users"
NumUsrsWhoClaimToBelongToIns = Usr_GetNumUsrsWhoClaimToBelongToIns (Ins->InsCod);
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
@ -1061,7 +1069,7 @@ static void Ins_ListInstitutionsForEdition (void)
if (!ICanEdit || if (!ICanEdit ||
Ins->Ctrs.Num || // Institution has centres Ins->Ctrs.Num || // Institution has centres
NumUsrsInCrssOfIns || // Institution has users NumUsrsInCrssOfIns || // Institution has users
Ins->NumUsrsWhoClaimToBelongToIns) NumUsrsWhoClaimToBelongToIns) // Institution has users
// Institution has centres or users ==> deletion forbidden // Institution has centres or users ==> deletion forbidden
Ico_PutIconRemovalNotAllowed (); Ico_PutIconRemovalNotAllowed ();
else else
@ -1137,7 +1145,7 @@ static void Ins_ListInstitutionsForEdition (void)
/* Number of users who claim to belong to this institution */ /* Number of users who claim to belong to this institution */
HTM_TD_Begin ("class=\"DAT RM\""); HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Ins->NumUsrsWhoClaimToBelongToIns); HTM_Unsigned (NumUsrsWhoClaimToBelongToIns);
HTM_TD_End (); HTM_TD_End ();
/* Number of centres */ /* Number of centres */
@ -1312,15 +1320,18 @@ void Ins_RemoveInstitution (void)
/***** Check if this institution has users *****/ /***** Check if this institution has users *****/
if (!Ins_CheckIfICanEdit (Ins_EditingIns)) if (!Ins_CheckIfICanEdit (Ins_EditingIns))
Lay_NoPermissionExit (); Lay_NoPermissionExit ();
else if (Ins_EditingIns->Ctrs.Num || else if (Ins_EditingIns->Ctrs.Num)
Ins_EditingIns->NumUsrsWhoClaimToBelongToIns) // Institution has centres ==> don't remove
// Institution has centres or users ==> don't remove
Ale_CreateAlert (Ale_WARNING,NULL, Ale_CreateAlert (Ale_WARNING,NULL,
Txt_To_remove_an_institution_you_must_first_remove_all_centres_and_users_in_the_institution); Txt_To_remove_an_institution_you_must_first_remove_all_centres_and_users_in_the_institution);
else if (Usr_GetNumUsrsInCrssOfIns (Rol_UNK,Ins_EditingIns->InsCod)) // Here Rol_UNK means "all users" else if (Usr_GetNumUsrsInCrssOfIns (Rol_UNK,Ins_EditingIns->InsCod)) // Here Rol_UNK means "all users"
// Institution has users ==> don't remove // Institution has users ==> don't remove
Ale_CreateAlert (Ale_WARNING,NULL, Ale_CreateAlert (Ale_WARNING,NULL,
Txt_To_remove_an_institution_you_must_first_remove_all_centres_and_users_in_the_institution); Txt_To_remove_an_institution_you_must_first_remove_all_centres_and_users_in_the_institution);
else if (Usr_GetNumUsrsWhoClaimToBelongToIns (Ins_EditingIns->InsCod))
// Institution has users ==> don't remove
Ale_CreateAlert (Ale_WARNING,NULL,
Txt_To_remove_an_institution_you_must_first_remove_all_centres_and_users_in_the_institution);
else // Institution has no users ==> remove it else // Institution has no users ==> remove it
{ {
/***** Remove all the threads and posts in forums of the institution *****/ /***** Remove all the threads and posts in forums of the institution *****/
@ -1348,6 +1359,7 @@ void Ins_RemoveInstitution (void)
/***** Flush caches *****/ /***** Flush caches *****/
Ins_FlushCacheShortNameOfInstitution (); Ins_FlushCacheShortNameOfInstitution ();
Ins_FlushCacheFullNameAndCtyOfInstitution (); Ins_FlushCacheFullNameAndCtyOfInstitution ();
Usr_FlushCacheNumUsrsWhoClaimToBelongToIns ();
Usr_FlushCacheNumUsrsInCrssOfIns (); Usr_FlushCacheNumUsrsInCrssOfIns ();
/***** Write message to show the change made *****/ /***** Write message to show the change made *****/
@ -2029,7 +2041,6 @@ static void Ins_EditingInstitutionConstructor (void)
Ins_EditingIns->Ctrs.SelectedOrder = Ctr_ORDER_DEFAULT; Ins_EditingIns->Ctrs.SelectedOrder = Ctr_ORDER_DEFAULT;
Ins_EditingIns->NumDpts = 0; Ins_EditingIns->NumDpts = 0;
Ins_EditingIns->NumDegs = 0; Ins_EditingIns->NumDegs = 0;
Ins_EditingIns->NumUsrsWhoClaimToBelongToIns = 0;
} }
static void Ins_EditingInstitutionDestructor (void) static void Ins_EditingInstitutionDestructor (void)

View File

@ -74,7 +74,6 @@ struct Instit
unsigned NumDegs; unsigned NumDegs;
unsigned NumCrss; unsigned NumCrss;
unsigned NumDpts; unsigned NumDpts;
unsigned NumUsrsWhoClaimToBelongToIns;
}; };
#define Ins_NUM_ORDERS 2 #define Ins_NUM_ORDERS 2

View File

@ -4562,15 +4562,32 @@ unsigned Usr_GetNumUsrsWhoClaimToBelongToCty (long CtyCod)
/******** Get number of users who claim to belong to an institution **********/ /******** Get number of users who claim to belong to an institution **********/
/*****************************************************************************/ /*****************************************************************************/
void Usr_FlushCacheNumUsrsWhoClaimToBelongToIns (void)
{
Gbl.Cache.NumUsrsWhoClaimToBelongToIns.InsCod = -1L;
Gbl.Cache.NumUsrsWhoClaimToBelongToIns.NumUsrs = 0;
}
unsigned Usr_GetNumUsrsWhoClaimToBelongToIns (long InsCod) unsigned Usr_GetNumUsrsWhoClaimToBelongToIns (long InsCod)
{ {
/***** Get the number of users in an institution from database *****/ /***** 1. Fast check: Trivial case *****/
return if (InsCod <= 0)
return 0;
/***** 2. Fast check: If cached... *****/
if (InsCod == Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.CtrCod)
return Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.NumUsrs;
/***** 3. Slow: number of users who claim to belong to an institution
from database *****/
Gbl.Cache.NumUsrsWhoClaimToBelongToIns.InsCod = InsCod;
Gbl.Cache.NumUsrsWhoClaimToBelongToIns.NumUsrs =
(unsigned) DB_QueryCOUNT ("can not get the number of users" (unsigned) DB_QueryCOUNT ("can not get the number of users"
" in an institution", " in an institution",
"SELECT COUNT(UsrCod) FROM usr_data" "SELECT COUNT(UsrCod) FROM usr_data"
" WHERE InsCod=%ld", " WHERE InsCod=%ld",
InsCod); InsCod);
return Gbl.Cache.NumUsrsWhoClaimToBelongToIns.NumUsrs;
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -422,6 +422,7 @@ long Usr_GetRamdomStdFromGrp (long GrpCod);
unsigned Usr_GetNumTchsCurrentInsInDepartment (long DptCod); unsigned Usr_GetNumTchsCurrentInsInDepartment (long DptCod);
unsigned Usr_GetNumUsrsWhoClaimToBelongToCty (long CtyCod); unsigned Usr_GetNumUsrsWhoClaimToBelongToCty (long CtyCod);
void Usr_FlushCacheNumUsrsWhoClaimToBelongToIns (void);
unsigned Usr_GetNumUsrsWhoClaimToBelongToIns (long InsCod); unsigned Usr_GetNumUsrsWhoClaimToBelongToIns (long InsCod);
void Usr_FlushCacheNumUsrsWhoClaimToBelongToCtr (void); void Usr_FlushCacheNumUsrsWhoClaimToBelongToCtr (void);
unsigned Usr_GetNumUsrsWhoClaimToBelongToCtr (long CtrCod); unsigned Usr_GetNumUsrsWhoClaimToBelongToCtr (long CtrCod);