diff --git a/swad_changelog.h b/swad_changelog.h index e95254ac..df08675b 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -598,10 +598,11 @@ TODO: DNI de un estudiante sale err TODO: BUG: Cuando un tipo de grupo sólo tiene un grupo, inscribirse es voluntario, el estudiante sólo puede pertenecer a un grupo, y se inscribe en él, debería poder desapuntarse. Ahora no puede. TODO: Salvador Romero Cortés: @acanas opción para editar posts */ -#define Log_PLATFORM_VERSION "SWAD 20.41.3 (2021-03-03)" +#define Log_PLATFORM_VERSION "SWAD 20.41.4 (2021-03-03)" #define CSS_FILE "swad20.33.9.css" #define JS_FILE "swad20.6.2.js" /* + Version 20.41.4: Mar 03, 2021 Code refactoring in timeline publications. (305577 lines) Version 20.41.3: Mar 03, 2021 Code refactoring in timeline publications. (305580 lines) Version 20.41.2: Mar 03, 2021 Code refactoring in timeline. (305569 lines) Version 20.41.1: Mar 03, 2021 Code refactoring in timeline posts. (305563 lines) diff --git a/swad_timeline_database.c b/swad_timeline_database.c index 1103840b..2b07f8b3 100644 --- a/swad_timeline_database.c +++ b/swad_timeline_database.c @@ -772,22 +772,18 @@ void TL_DB_CreateSubQueryAlreadyExists (const struct TL_Timeline *Timeline, /***** Create subqueries with range of publications to get from tl_pubs ******/ /*****************************************************************************/ -void TL_DB_CreateSubQueryRangeBottom (const struct TL_Pub_RangePubsToGet *RangePubsToGet, - struct TL_Pub_SubQueries *SubQueries) +void TL_DB_CreateSubQueryRangeBottom (long Bottom,struct TL_Pub_SubQueries *SubQueries) { - if (RangePubsToGet->Bottom > 0) - sprintf (SubQueries->RangeBottom,"tl_pubs.PubCod>%ld AND ", - RangePubsToGet->Bottom); + if (Bottom > 0) + sprintf (SubQueries->RangeBottom,"tl_pubs.PubCod>%ld AND ",Bottom); else SubQueries->RangeBottom[0] = '\0'; } -void TL_DB_CreateSubQueryRangeTop (const struct TL_Pub_RangePubsToGet *RangePubsToGet, - struct TL_Pub_SubQueries *SubQueries) +void TL_DB_CreateSubQueryRangeTop (long Top,struct TL_Pub_SubQueries *SubQueries) { - if (RangePubsToGet->Top > 0) - sprintf (SubQueries->RangeTop,"tl_pubs.PubCod<%ld AND ", - RangePubsToGet->Top); + if (Top > 0) + sprintf (SubQueries->RangeTop,"tl_pubs.PubCod<%ld AND ",Top); else SubQueries->RangeTop[0] = '\0'; } diff --git a/swad_timeline_database.h b/swad_timeline_database.h index d697b992..b164cc4d 100644 --- a/swad_timeline_database.h +++ b/swad_timeline_database.h @@ -105,10 +105,8 @@ void TL_DB_CreateSubQueryPublishers (const struct TL_Timeline *Timeline, struct TL_Pub_SubQueries *SubQueries); void TL_DB_CreateSubQueryAlreadyExists (const struct TL_Timeline *Timeline, struct TL_Pub_SubQueries *SubQueries); -void TL_DB_CreateSubQueryRangeBottom (const struct TL_Pub_RangePubsToGet *RangePubsToGet, - struct TL_Pub_SubQueries *SubQueries); -void TL_DB_CreateSubQueryRangeTop (const struct TL_Pub_RangePubsToGet *RangePubsToGet, - struct TL_Pub_SubQueries *SubQueries); +void TL_DB_CreateSubQueryRangeBottom (long Bottom,struct TL_Pub_SubQueries *SubQueries); +void TL_DB_CreateSubQueryRangeTop (long Top,struct TL_Pub_SubQueries *SubQueries); unsigned TL_DB_SelectTheMostRecentPub (const struct TL_Pub_SubQueries *SubQueries, MYSQL_RES **mysql_res); unsigned TL_DB_GetDataOfPubByCod (long PubCod,MYSQL_RES **mysql_res); diff --git a/swad_timeline_publication.c b/swad_timeline_publication.c index 6893f58b..a6a9a046 100644 --- a/swad_timeline_publication.c +++ b/swad_timeline_publication.c @@ -81,6 +81,9 @@ void TL_Pub_GetListPubsToShowInTimeline (struct TL_Timeline *Timeline) unsigned NumPub; struct TL_Pub_Publication *Pub; + /***** Initialize range of publications *****/ + TL_Pub_InitializeRangeOfPubs (Timeline->WhatToGet,&RangePubsToGet); + /***** Clear timeline for this session in database *****/ if (Timeline->WhatToGet == TL_GET_RECENT_TIMELINE) TL_DB_ClearTimelineNotesOfSessionFromDB (); @@ -100,30 +103,12 @@ void TL_Pub_GetListPubsToShowInTimeline (struct TL_Timeline *Timeline) /* Create subquery to get only notes not present in timeline */ TL_DB_CreateSubQueryAlreadyExists (Timeline,&SubQueries); - /***** Get the publications in timeline *****/ - /* Initialize range of pubs */ - TL_Pub_InitializeRangeOfPubs (Timeline->WhatToGet,&RangePubsToGet); - /* Create subquery with bottom range of publications to get from tl_pubs. - Bottom pub. code remains unchanged in all iterations of the next loop. */ - TL_DB_CreateSubQueryRangeBottom (&RangePubsToGet,&SubQueries); + Bottom pub. code remains unchanged in all iterations of the loop. */ + TL_DB_CreateSubQueryRangeBottom (RangePubsToGet.Bottom,&SubQueries); - /* With the current approach, we select one by one - the publications and notes in a loop. In each iteration, - we get the most recent publication (original, shared or commment) - of every set of publications corresponding to the same note, - checking that the note is not already retrieved. - After getting a publication, its note code is stored - in order to not get it again. - - As an alternative, we tried to get the maximum PubCod, - i.e more recent publication (original, shared or commment), - of every set of publications corresponding to the same note: - "SELECT MAX(PubCod) AS NewestPubCod FROM tl_pubs ... - " GROUP BY NotCod ORDER BY NewestPubCod DESC LIMIT ..." - but this query is slow (several seconds) with a big table. - - Chained list of publications: + /***** Initialize list of publications *****/ + /* Chained list of publications: Timeline->Pubs.Top Pub #0 ______ ______ Pub #1 @@ -142,13 +127,29 @@ void TL_Pub_GetListPubsToShowInTimeline (struct TL_Timeline *Timeline) Timeline->Pubs.Top = Timeline->Pubs.Bottom = NULL; + /***** Get the publications in timeline *****/ + /* With the current approach, we select one by one + the publications and notes in a loop. In each iteration, + we get the most recent publication (original, shared or commment) + of every set of publications corresponding to the same note, + checking that the note is not already retrieved. + After getting a publication, its note code is stored + in order to not get it again. + + As an alternative, we tried to get the maximum PubCod, + i.e more recent publication (original, shared or commment), + of every set of publications corresponding to the same note: + "SELECT MAX(PubCod) AS NewestPubCod FROM tl_pubs ... + " GROUP BY NotCod ORDER BY NewestPubCod DESC LIMIT ..." + but this query is slow (several seconds) with a big table. + */ for (NumPub = 0; NumPub < MaxPubsToGet; NumPub++) { /* Create subquery with top range of publications to get from tl_pubs In each iteration of this loop, top publication code is changed to a lower value */ - TL_DB_CreateSubQueryRangeTop (&RangePubsToGet,&SubQueries); + TL_DB_CreateSubQueryRangeTop (RangePubsToGet.Top,&SubQueries); /* Select the most recent publication from tl_pubs */ Pub = TL_Pub_SelectTheMostRecentPub (&SubQueries);