Version19.112.6

This commit is contained in:
Antonio Cañas Vargas 2020-01-05 01:46:45 +01:00
parent d2d0bd079a
commit d664dd1982
9 changed files with 102 additions and 110 deletions

View File

@ -384,7 +384,7 @@ static void Ctr_ListOneCentreForSeeing (struct Centre *Ctr,unsigned NumCtr)
/***** Number of users who claim to belong to this centre *****/
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
HTM_Unsigned (Ctr->NumUsrsWhoClaimToBelongToCtr);
HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToCtr (Ctr->CtrCod));
HTM_TD_End ();
/***** Place *****/
@ -411,7 +411,7 @@ static void Ctr_ListOneCentreForSeeing (struct Centre *Ctr,unsigned NumCtr)
/***** Number of courses *****/
HTM_TD_Begin ("class=\"%s RM %s\"",TxtClassNormal,BgColor);
HTM_Unsigned (Ctr->NumCrss);
HTM_Unsigned (Crs_GetNumCrssInCtr (Ctr->CtrCod));
HTM_TD_End ();
/***** Number of users in courses of this centre *****/
@ -548,43 +548,21 @@ void Ctr_GetListCentres (long InsCod)
/***** Get centres from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get centres",
"(SELECT centres.CtrCod," // row[ 0]
"centres.InsCod," // row[ 1]
"centres.PlcCod," // row[ 2]
"centres.Status," // row[ 3]
"centres.RequesterUsrCod," // row[ 4]
"centres.Latitude," // row[ 5]
"centres.Longitude," // row[ 6]
"centres.Altitude," // row[ 7]
"centres.ShortName," // row[ 8]
"centres.FullName," // row[ 9]
"centres.WWW," // row[10]
"COUNT(DISTINCT usr_data.UsrCod)"
" AS NumUsrs" // row[11]
" FROM centres,usr_data"
" WHERE centres.InsCod=%ld"
" AND centres.CtrCod=usr_data.CtrCod"
" GROUP BY centres.CtrCod)"
" UNION "
"(SELECT CtrCod," // row[ 0]
"InsCod," // row[ 1]
"PlcCod," // row[ 2]
"Status," // row[ 3]
"RequesterUsrCod," // row[ 4]
"Latitude," // row[ 5]
"Longitude," // row[ 6]
"Altitude," // row[ 7]
"ShortName," // row[ 8]
"FullName," // row[ 9]
"WWW," // row[10]
"0 AS NumUsrs" // row[11]
"SELECT CtrCod," // row[ 0]
"InsCod," // row[ 1]
"PlcCod," // row[ 2]
"Status," // row[ 3]
"RequesterUsrCod," // row[ 4]
"Latitude," // row[ 5]
"Longitude," // row[ 6]
"Altitude," // row[ 7]
"ShortName," // row[ 8]
"FullName," // row[ 9]
"WWW" // row[10]
" FROM centres"
" WHERE centres.InsCod=%ld"
" AND CtrCod NOT IN"
" (SELECT DISTINCT CtrCod FROM usr_data))"
" WHERE InsCod=%ld"
" ORDER BY %s",
InsCod,
InsCod,
OrderBySubQuery[Gbl.Hierarchy.Ins.Ctrs.SelectedOrder]);
if (NumRows) // Centres found...
@ -610,9 +588,6 @@ void Ctr_GetListCentres (long InsCod)
/* Get number of degrees in this centre */
Ctr->Degs.Num = Deg_GetNumDegsInCtr (Ctr->CtrCod);
/* Get number of courses in this centre */
Ctr->NumCrss = Crs_GetNumCrssInCtr (Ctr->CtrCod);
}
}
else
@ -642,50 +617,26 @@ bool Ctr_GetDataOfCentreByCod (struct Centre *Ctr,
Ctr->ShrtName[0] = '\0';
Ctr->FullName[0] = '\0';
Ctr->WWW[0] = '\0';
Ctr->NumUsrsWhoClaimToBelongToCtr = 0;
Ctr->Degs.Num =
Ctr->NumCrss = 0;
Ctr->Degs.Num = 0;
/***** Check if centre code is correct *****/
if (Ctr->CtrCod > 0)
{
/***** Get data of a centre from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get data of a centre",
"(SELECT centres.CtrCod," // row[ 0]
"centres.InsCod," // row[ 1]
"centres.PlcCod," // row[ 2]
"centres.Status," // row[ 3]
"centres.RequesterUsrCod," // row[ 4]
"centres.Latitude," // row[ 5]
"centres.Longitude," // row[ 6]
"centres.Altitude," // row[ 7]
"centres.ShortName," // row[ 8]
"centres.FullName," // row[ 9]
"centres.WWW," // row[10]
"COUNT(DISTINCT usr_data.UsrCod)"
" AS NumUsrs" // row[11]
" FROM centres,usr_data"
" WHERE centres.CtrCod=%ld"
" AND centres.CtrCod=usr_data.CtrCod"
" GROUP BY centres.CtrCod)"
" UNION "
"(SELECT CtrCod," // row[ 0]
"InsCod," // row[ 1]
"PlcCod," // row[ 2]
"Status," // row[ 3]
"RequesterUsrCod," // row[ 4]
"Latitude," // row[ 5]
"Longitude," // row[ 6]
"Altitude," // row[ 7]
"ShortName," // row[ 8]
"FullName," // row[ 9]
"WWW," // row[10]
"0 AS NumUsrs" // row[11]
"SELECT CtrCod," // row[ 0]
"InsCod," // row[ 1]
"PlcCod," // row[ 2]
"Status," // row[ 3]
"RequesterUsrCod," // row[ 4]
"Latitude," // row[ 5]
"Longitude," // row[ 6]
"Altitude," // row[ 7]
"ShortName," // row[ 8]
"FullName," // row[ 9]
"WWW" // row[10]
" FROM centres"
" WHERE CtrCod=%ld"
" AND CtrCod NOT IN"
" (SELECT DISTINCT CtrCod FROM usr_data))",
Ctr->CtrCod,
" WHERE CtrCod=%ld",
Ctr->CtrCod);
if (NumRows) // Centre found...
{
@ -695,14 +646,9 @@ bool Ctr_GetDataOfCentreByCod (struct Centre *Ctr,
/* Get extra data */
if (GetExtraData == Ctr_GET_EXTRA_DATA)
{
/* Get number of degrees in this centre */
Ctr->Degs.Num = Deg_GetNumDegsInCtr (Ctr->CtrCod);
/* Get number of courses in this centre */
Ctr->NumCrss = Crs_GetNumCrssInCtr (Ctr->CtrCod);
}
/* Set return value */
CtrFound = true;
}
@ -757,10 +703,6 @@ static void Ctr_GetDataOfCentreFromRow (struct Centre *Ctr,MYSQL_ROW row)
/***** Get the URL of the centre (row[10]) *****/
Str_Copy (Ctr->WWW,row[10],
Cns_MAX_BYTES_WWW);
/***** Get number of users who claim to belong to this centre (row[11]) *****/
if (sscanf (row[11],"%u",&Ctr->NumUsrsWhoClaimToBelongToCtr) != 1)
Ctr->NumUsrsWhoClaimToBelongToCtr = 0;
}
/*****************************************************************************/
@ -940,14 +882,14 @@ static void Ctr_ListCentresForEdition (void)
HTM_TD_Begin ("class=\"BM\"");
if (!ICanEdit)
Ico_PutIconRemovalNotAllowed ();
else if (Ctr->Degs.Num) // Centre has degrees
else if (Ctr->Degs.Num) // Centre has degrees
Ico_PutIconRemovalNotAllowed ();
else if (Ctr->NumUsrsWhoClaimToBelongToCtr) // Centre has users who claim to belong to it
else if (Usr_GetNumUsrsWhoClaimToBelongToCtr (Ctr->CtrCod)) // Centre has users who claim to belong to it
Ico_PutIconRemovalNotAllowed ();
else if (Usr_GetNumUsrsInCrssOfCtr (Rol_UNK, // Here Rol_UNK means "all users"
Ctr->CtrCod)) // Centre has users
Ctr->CtrCod)) // Centre has users
Ico_PutIconRemovalNotAllowed ();
else // I can remove centre
else // I can remove centre
{
Frm_StartForm (ActRemCtr);
Ctr_PutParamOtherCtrCod (Ctr->CtrCod);
@ -1047,7 +989,7 @@ static void Ctr_ListCentresForEdition (void)
/* Number of users who claim to belong to this centre */
HTM_TD_Begin ("class=\"DAT RM\"");
HTM_Unsigned (Ctr->NumUsrsWhoClaimToBelongToCtr);
HTM_Unsigned (Usr_GetNumUsrsWhoClaimToBelongToCtr (Ctr->CtrCod));
HTM_TD_End ();
/* Number of degrees */
@ -1209,13 +1151,16 @@ void Ctr_RemoveCentre (void)
Ctr_GetDataOfCentreByCod (Ctr_EditingCtr,Ctr_GET_EXTRA_DATA);
/***** Check if this centre has teachers *****/
if (Ctr_EditingCtr->Degs.Num) // Centre has degrees
Ale_ShowAlert (Ale_WARNING,Txt_To_remove_a_centre_you_must_first_remove_all_degrees_and_teachers_in_the_centre);
else if (Ctr_EditingCtr->NumUsrsWhoClaimToBelongToCtr) // Centre has users who claim to belong to it
Ale_ShowAlert (Ale_WARNING,Txt_To_remove_a_centre_you_must_first_remove_all_degrees_and_teachers_in_the_centre);
else if (Usr_GetNumUsrsInCrssOfCtr (Rol_UNK, // Here Rol_UNK means "all users"
Ctr_EditingCtr->CtrCod)) // Centre has users
Ale_ShowAlert (Ale_WARNING,Txt_To_remove_a_centre_you_must_first_remove_all_degrees_and_teachers_in_the_centre);
if (Ctr_EditingCtr->Degs.Num) // Centre has degrees
Ale_ShowAlert (Ale_WARNING,
Txt_To_remove_a_centre_you_must_first_remove_all_degrees_and_teachers_in_the_centre);
else if (Usr_GetNumUsrsWhoClaimToBelongToCtr (Ctr_EditingCtr->CtrCod)) // Centre has users who claim to belong to it
Ale_ShowAlert (Ale_WARNING,
Txt_To_remove_a_centre_you_must_first_remove_all_degrees_and_teachers_in_the_centre);
else if (Usr_GetNumUsrsInCrssOfCtr (Rol_UNK, // Here Rol_UNK means "all users"
Ctr_EditingCtr->CtrCod)) // Centre has users
Ale_ShowAlert (Ale_WARNING,
Txt_To_remove_a_centre_you_must_first_remove_all_degrees_and_teachers_in_the_centre);
else // Centre has no degrees or users ==> remove it
{
/***** Remove all the threads and posts in forums of the centre *****/
@ -1244,7 +1189,9 @@ void Ctr_RemoveCentre (void)
Ctr_EditingCtr->CtrCod);
/***** Flush caches *****/
Ctr_FlushCacheNumUsrsInCrssOfCtr ();
Crs_FlushCacheNumCrssInCtr ();
Usr_FlushCacheNumUsrsWhoClaimToBelongToCtr ();
Usr_FlushCacheNumUsrsInCrssOfCtr ();
/***** Write message to show the change made *****/
Ale_CreateAlert (Ale_SUCCESS,NULL,
@ -2056,8 +2003,6 @@ static void Ctr_EditingCentreConstructor (void)
Ctr_EditingCtr->WWW[0] = '\0';
Ctr_EditingCtr->Degs.Num = 0;
Ctr_EditingCtr->Degs.Lst = NULL;
Ctr_EditingCtr->NumCrss = 0;
Ctr_EditingCtr->NumUsrsWhoClaimToBelongToCtr = 0;
}
static void Ctr_EditingCentreDestructor (void)

View File

@ -72,8 +72,6 @@ struct Centre
char FullName[Hie_MAX_BYTES_FULL_NAME + 1];
char WWW[Cns_MAX_BYTES_WWW + 1];
struct ListDegrees Degs; // List of degrees in this centre
unsigned NumCrss; // Number of courses in this centre
unsigned NumUsrsWhoClaimToBelongToCtr; // Number of users who claim to belong in this centre
};
#define Ctr_NUM_ORDERS 2

View File

@ -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.4 (2020-01-05)"
#define Log_PLATFORM_VERSION "SWAD 19.112.6 (2020-01-05)"
#define CSS_FILE "swad19.112.css"
#define JS_FILE "swad19.91.1.js"
/*
@ -501,6 +501,8 @@ ps2pdf source.ps destination.pdf
// TODO: No se puede entrar con DNI '1' suponiendo que no tenga password ¿por qué?
// TODO: Mapas más estrechos en móvil
Version 19.112.6: Jan 05, 2020 Optimization in number of courses in a centre. (278374 lines)
Version 19.112.5: Jan 05, 2020 Optimization in number of users who claim to belong to a centre. (278361 lines)
Version 19.112.4: Jan 05, 2020 Optimization in number of users in courses of a centre. (278385 lines)
Version 19.112.3: Jan 04, 2020 Fixed bug in hierarchy. (278357 lines)
Version 19.112.2: Jan 04, 2020 Changing action descriptions from database to swad-core. Not finished. (278351 lines)

View File

@ -444,15 +444,31 @@ unsigned Crs_GetNumCrssInIns (long InsCod)
/******************** Get number of courses in a centre **********************/
/*****************************************************************************/
void Crs_FlushCacheNumCrssInCtr (void)
{
Gbl.Cache.NumCrssInCtr.CtrCod = -1L;
Gbl.Cache.NumCrssInCtr.NumCrss = 0;
}
unsigned Crs_GetNumCrssInCtr (long CtrCod)
{
/***** Get number of courses in a degree from database *****/
return
/***** 1. Fast check: Trivial case *****/
if (CtrCod <= 0)
return 0;
/***** 2. Fast check: If cached... *****/
if (CtrCod == Gbl.Cache.NumCrssInCtr.CtrCod)
return Gbl.Cache.NumCrssInCtr.NumCrss;
/***** 3. Slow: number of courses in a centre from database *****/
Gbl.Cache.NumCrssInCtr.CtrCod = CtrCod;
Gbl.Cache.NumCrssInCtr.NumCrss =
(unsigned) DB_QueryCOUNT ("can not get the number of courses in a centre",
"SELECT COUNT(*) FROM degrees,courses"
" WHERE degrees.CtrCod=%ld"
" AND degrees.DegCod=courses.DegCod",
CtrCod);
return Gbl.Cache.NumCrssInCtr.NumCrss;
}
/*****************************************************************************/

View File

@ -103,6 +103,7 @@ void Crs_ShowIntroduction (void);
unsigned Crs_GetNumCrssTotal (void);
unsigned Crs_GetNumCrssInCty (long CtyCod);
unsigned Crs_GetNumCrssInIns (long InsCod);
void Crs_FlushCacheNumCrssInCtr (void);
unsigned Crs_GetNumCrssInCtr (long CtrCod);
unsigned Crs_GetNumCrssInDeg (long DegCod);
unsigned Crs_GetNumCrssWithUsrs (Rol_Role_t Role,const char *SubQuery);

View File

@ -412,7 +412,9 @@ void Gbl_InitializeGlobals (void)
Cty_FlushCacheCountryName ();
Ins_FlushCacheShortNameOfInstitution ();
Ins_FlushCacheFullNameAndCtyOfInstitution ();
Ctr_FlushCacheNumUsrsInCrssOfCtr ();
Crs_FlushCacheNumCrssInCtr ();
Usr_FlushCacheNumUsrsWhoClaimToBelongToCtr ();
Usr_FlushCacheNumUsrsInCrssOfCtr ();
Usr_FlushCacheUsrIsSuperuser ();
Usr_FlushCacheUsrBelongsToIns ();
Usr_FlushCacheUsrBelongsToCtr ();

View File

@ -772,6 +772,16 @@ struct Globals
char ShrtName[Hie_MAX_BYTES_SHRT_NAME + 1];
char CtyName[Hie_MAX_BYTES_FULL_NAME + 1];
} InstitutionShrtNameAndCty;
struct
{
long CtrCod;
unsigned NumCrss;
} NumCrssInCtr;
struct
{
long CtrCod;
unsigned NumUsrs;
} NumUsrsWhoClaimToBelongToCtr;
struct
{
Rol_Role_t Role;

View File

@ -4200,7 +4200,7 @@ unsigned Usr_GetNumUsrsInCrssOfDeg (Rol_Role_t Role,long DegCod)
/*****************************************************************************/
// Here Rol_UNK means any user (students, non-editing teachers or teachers)
void Ctr_FlushCacheNumUsrsInCrssOfCtr (void)
void Usr_FlushCacheNumUsrsInCrssOfCtr (void)
{
Gbl.Cache.NumUsrsInCrssOfCtr.Role = Rol_UNK;
Gbl.Cache.NumUsrsInCrssOfCtr.CtrCod = -1L;
@ -4440,14 +4440,31 @@ unsigned Usr_GetNumUsrsWhoClaimToBelongToIns (long InsCod)
/*********** Get number of users who claim to belong to a centre *************/
/*****************************************************************************/
void Usr_FlushCacheNumUsrsWhoClaimToBelongToCtr (void)
{
Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.CtrCod = -1L;
Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.NumUsrs = 0;
}
unsigned Usr_GetNumUsrsWhoClaimToBelongToCtr (long CtrCod)
{
/***** Get the number of users in a centre from database *****/
return
/***** 1. Fast check: Trivial case *****/
if (CtrCod <= 0)
return 0;
/***** 2. Fast check: If cached... *****/
if (CtrCod == Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.CtrCod)
return Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.NumUsrs;
/***** 3. Slow: number of users who claim to belong to a centre
from database *****/
Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.CtrCod = CtrCod;
Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.NumUsrs =
(unsigned) DB_QueryCOUNT ("can not get the number of users in a centre",
"SELECT COUNT(UsrCod) FROM usr_data"
" WHERE CtrCod=%ld",
CtrCod);
return Gbl.Cache.NumUsrsWhoClaimToBelongToCtr.NumUsrs;
}
/*****************************************************************************/

View File

@ -409,7 +409,7 @@ void Usr_WriteRowUsrMainData (unsigned NumUsr,struct UsrData *UsrDat,
unsigned Usr_GetNumUsrsInCrs (Rol_Role_t Role,long CrsCod);
unsigned Usr_GetNumUsrsInCrssOfDeg (Rol_Role_t Role,long DegCod);
void Ctr_FlushCacheNumUsrsInCrssOfCtr (void);
void Usr_FlushCacheNumUsrsInCrssOfCtr (void);
unsigned Usr_GetNumUsrsInCrssOfCtr (Rol_Role_t Role,long CtrCod);
unsigned Usr_GetNumUsrsInCrssOfIns (Rol_Role_t Role,long InsCod);
unsigned Usr_GetNumUsrsInCrssOfCty (Rol_Role_t Role,long CtyCod);
@ -420,6 +420,7 @@ long Usr_GetRamdomStdFromGrp (long GrpCod);
unsigned Usr_GetNumTchsCurrentInsInDepartment (long DptCod);
unsigned Usr_GetNumUsrsWhoClaimToBelongToCty (long CtyCod);
unsigned Usr_GetNumUsrsWhoClaimToBelongToIns (long InsCod);
void Usr_FlushCacheNumUsrsWhoClaimToBelongToCtr (void);
unsigned Usr_GetNumUsrsWhoClaimToBelongToCtr (long CtrCod);
unsigned Usr_GetNumberOfTeachersInCentre (long CtrCod);