Version 21.58: Nov 21, 2021 Code refactoring in timeline.

This commit is contained in:
acanas 2021-11-21 01:22:59 +01:00
parent e3a4494721
commit 733ae0e86d
17 changed files with 319 additions and 299 deletions

View File

@ -937,8 +937,30 @@ function readNewTimelineData () {
// (move all the LI elements (notes) in UL 'just_now_timeline_list'...
// ...to the top of UL 'new_timeline_list')
var newTimeline = document.getElementById('new_timeline_list'); // Access to UL with the new timeline
for (var i=0; i<numNotesJustGot; i++)
newTimeline.insertBefore(justNowTimeline.lastChild, newTimeline.firstChild);
for (var i=1; i<=numNotesJustGot; i++) {
// Check if the last child (the oldest) in just now timeline...
// ...is the last ocurrence of the note
var mostRecentOcurrenceOfNote = true;
var lastChildIndex = numNotesJustGot - i;
var noteCode = justNowTimeline.lastChild.dataset.noteCode;
for (var j=0; j<lastChildIndex; j++)
if (justNowTimeline.childNodes[j].dataset.noteCode == noteCode) {
mostRecentOcurrenceOfNote = false;
break;
}
// Move or remove node from new timeline
if (mostRecentOcurrenceOfNote) {
// Move node from just now timeline to new timeline
newTimeline.insertBefore(justNowTimeline.lastChild, newTimeline.firstChild);
newTimeline.firstChild.className += " Tml_NEW_PUB";
}
else
// Remove last child (because is repeated in more recent pubs)
justNowTimeline.removeChild(justNowTimeline.lastChild);
}
// Update number of new posts
var viewNewPostsCount = document.getElementById('view_new_posts_count');
@ -975,10 +997,9 @@ function moveNewTimelineToTimeline () {
// ...is the last ocurrence of the note
var mostRecentOcurrenceOfNote = true;
var lastChildIndex = numNewNotes - i;
var noteCode = newTimeline.lastChild.dataset.noteCode;
for (var j=0; j<lastChildIndex; j++)
if (newTimeline.childNodes[j].dataset.noteCode ==
newTimeline.lastChild.dataset.noteCode) {
if (newTimeline.childNodes[j].dataset.noteCode == noteCode) {
mostRecentOcurrenceOfNote = false;
break;
}

View File

@ -13522,4 +13522,41 @@ WHERE NotCod NOT IN (SELECT NotCod FROM tml_tmp_just_retrieved_notes)
ORDER BY PubCod DESC
LIMIT 1;
CREATE TEMPORARY TABLE tml_tmp_just_retrieved_notes (NotCod BIGINT NOT NULL,UNIQUE INDEX(NotCod)) ENGINE=MEMORY;
CREATE TEMPORARY TABLE tml_tmp_visible_timeline (NotCod BIGINT NOT NULL,UNIQUE INDEX(NotCod)) ENGINE=MEMORY SELECT NotCod FROM tml_timelines WHERE SessionId='%s',Gbl.Session.Id);
CREATE TEMPORARY TABLE fol_tmp_me_and_followed (UsrCod INT NOT NULL,UNIQUE INDEX(UsrCod)) ENGINE=MEMORY SELECT 1 AS UsrCod UNION SELECT FollowedCod AS UsrCod FROM usr_follow WHERE FollowerCod=1;
CREATE TEMPORARY TABLE fol_tmp_me_and_followed_2 (UsrCod INT NOT NULL,UNIQUE INDEX(UsrCod)) ENGINE=MEMORY SELECT 1 UNION SELECT FollowedCod FROM usr_follow WHERE FollowerCod=1;
SELECT tml_pubs.PubCod,
tml_pubs.NotCod,
tml_pubs.PublisherCod,
tml_pubs.PubType
FROM tml_pubs,
fol_tmp_me_and_followed
WHERE tml_pubs.PublisherCod=fol_tmp_me_and_followed.UsrCod
AND tml_pubs.NotCod NOT IN
(SELECT NotCod
FROM tml_tmp_just_retrieved_notes)
ORDER BY PubCod DESC
LIMIT 1;
"SELECT tml_pubs.PubCod," // row[0]
"tml_pubs.NotCod," // row[1]
"tml_pubs.PublisherCod," // row[2]
"tml_pubs.PubType" // row[3]
" FROM tml_pubs%s"
" WHERE tml_pubs.PublisherCod=fol_tmp_me_and_followed.UsrCod
AND "
" ORDER BY tml_pubs.PubCod DESC"
" LIMIT 1",
SubQueries->Publishers.Table,
SubQueries->RangeBottom,
SubQueries->RangeTop,
SubQueries->Publishers.SubQuery,
SubQueries->AlreadyExists);

View File

@ -1722,43 +1722,40 @@ unsigned Brw_DB_SearchFilesInMyCrss (MYSQL_RES **mysql_res,
/***** Create temporary tables with codes of files in documents and shared areas accessible by me.
It is necessary to speed up the second query *****/
DB_Query ("can not remove temporary tables",
"DROP TEMPORARY TABLE IF EXISTS my_files_crs,"
"my_files_grp");
DB_DropTmpTable ("my_files_crs");
DB_DropTmpTable ("my_files_grp");
DB_Query ("can not create temporary table",
"CREATE TEMPORARY TABLE my_files_crs"
" (FilCod INT NOT NULL,"
"UNIQUE INDEX(FilCod))"
" ENGINE=MEMORY"
" SELECT brw_files.FilCod"
" FROM crs_users,"
"brw_files"
" WHERE crs_users.UsrCod=%ld"
" AND crs_users.CrsCod=brw_files.Cod"
" AND brw_files.FileBrowser IN (%u,%u,%u,%u)",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Brw_ADMI_DOC_CRS,
(unsigned) Brw_ADMI_TCH_CRS,
(unsigned) Brw_ADMI_SHR_CRS,
(unsigned) Brw_ADMI_MRK_CRS);
DB_CreateTmpTable ("CREATE TEMPORARY TABLE my_files_crs"
" (FilCod INT NOT NULL,"
"UNIQUE INDEX(FilCod))"
" ENGINE=MEMORY"
" SELECT brw_files.FilCod"
" FROM crs_users,"
"brw_files"
" WHERE crs_users.UsrCod=%ld"
" AND crs_users.CrsCod=brw_files.Cod"
" AND brw_files.FileBrowser IN (%u,%u,%u,%u)",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Brw_ADMI_DOC_CRS,
(unsigned) Brw_ADMI_TCH_CRS,
(unsigned) Brw_ADMI_SHR_CRS,
(unsigned) Brw_ADMI_MRK_CRS);
DB_Query ("can not create temporary table",
"CREATE TEMPORARY TABLE my_files_grp"
" (FilCod INT NOT NULL,"
"UNIQUE INDEX(FilCod))"
" ENGINE=MEMORY"
" SELECT brw_files.FilCod"
" FROM grp_users,"
"brw_files"
" WHERE grp_users.UsrCod=%ld"
" AND grp_users.GrpCod=brw_files.Cod"
" AND brw_files.FileBrowser IN (%u,%u,%u,%u)",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Brw_ADMI_DOC_GRP,
(unsigned) Brw_ADMI_TCH_GRP,
(unsigned) Brw_ADMI_SHR_GRP,
(unsigned) Brw_ADMI_MRK_GRP);
DB_CreateTmpTable ("CREATE TEMPORARY TABLE my_files_grp"
" (FilCod INT NOT NULL,"
"UNIQUE INDEX(FilCod))"
" ENGINE=MEMORY"
" SELECT brw_files.FilCod"
" FROM grp_users,"
"brw_files"
" WHERE grp_users.UsrCod=%ld"
" AND grp_users.GrpCod=brw_files.Cod"
" AND brw_files.FileBrowser IN (%u,%u,%u,%u)",
Gbl.Usrs.Me.UsrDat.UsrCod,
(unsigned) Brw_ADMI_DOC_GRP,
(unsigned) Brw_ADMI_TCH_GRP,
(unsigned) Brw_ADMI_SHR_GRP,
(unsigned) Brw_ADMI_MRK_GRP);
/***** Build the query *****/
NumFiles = (unsigned)
@ -1853,9 +1850,8 @@ unsigned Brw_DB_SearchFilesInMyCrss (MYSQL_RES **mysql_res,
RangeQuery);
/***** Drop temporary tables *****/
DB_Query ("can not remove temporary table",
"DROP TEMPORARY TABLE IF EXISTS my_files_crs,"
"my_files_grp");
DB_DropTmpTable ("my_files_crs");
DB_DropTmpTable ("my_files_grp");
return NumFiles;
}

View File

@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
*/
#define Log_PLATFORM_VERSION "SWAD 21.57.5 (2021-11-18)"
#define Log_PLATFORM_VERSION "SWAD 21.58 (2021-11-21)"
#define CSS_FILE "swad21.57.css"
#define JS_FILE "swad21.57.js"
#define JS_FILE "swad21.58.js"
/*
TODO: Rename CENTRE to CENTER in help wiki.
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
Version 21.58: Nov 21, 2021 Code refactoring in timeline. (319157 lines)
Version 21.57.5: Nov 18, 2021 Code refactoring related to check if user logged is me. (319174 lines)
Version 21.57.4: Nov 17, 2021 Code refactoring in timeline. (319235 lines)
Version 21.57.3: Nov 17, 2021 Code refactoring in timeline. (319225 lines)

View File

@ -3724,7 +3724,7 @@ mysql> DESCRIBE usr_webs;
static void DB_CreateTable (const char *Query)
{
HTM_LI_Begin ("class=\"DAT\"");
HTM_Txt (Query);
HTM_Txt (Query);
HTM_LI_End ();
if (mysql_query (&Gbl.mysql,Query))
@ -4224,6 +4224,36 @@ void DB_QueryDELETE (const char *MsgError,const char *fmt,...)
DB_ExitOnMySQLError (MsgError);
}
/*****************************************************************************/
/**************************** Create temporary table *************************/
/*****************************************************************************/
void DB_CreateTmpTable (const char *fmt,...)
{
va_list ap;
int NumBytesPrinted;
char *Query;
int Result;
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Query,fmt,ap);
va_end (ap);
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
/***** Query database and free query string pointer *****/
Result = mysql_query (&Gbl.mysql,Query); // Returns 0 on success
free (Query);
if (Result)
DB_ExitOnMySQLError ("can not create temporary table");
}
void DB_DropTmpTable (const char *Table)
{
DB_Query ("can not remove temporary table",
"DROP TEMPORARY TABLE IF EXISTS %s",Table);
}
/*****************************************************************************/
/**************** Make other kind of query from database *********************/
/*****************************************************************************/

View File

@ -69,6 +69,9 @@ void DB_QueryUPDATE (const char *MsgError,const char *fmt,...);
void DB_QueryDELETE (const char *MsgError,const char *fmt,...);
void DB_CreateTmpTable (const char *fmt,...);
void DB_DropTmpTable (const char *Table);
void DB_Query (const char *MsgError,const char *fmt,...);
void DB_FreeMySQLResult (MYSQL_RES **mysql_res);

View File

@ -78,24 +78,23 @@ void Enr_DB_AcceptUsrInCrs (long UsrCod,long CrsCod)
void Enr_DB_CreateTmpTableMyCourses (void)
{
DB_Query ("can not create temporary table",
"CREATE TEMPORARY TABLE IF NOT EXISTS my_courses_tmp"
" (CrsCod INT NOT NULL,"
"Role TINYINT NOT NULL,"
"DegCod INT NOT NULL,"
"UNIQUE INDEX(CrsCod,Role,DegCod)) ENGINE=MEMORY"
" SELECT crs_users.CrsCod,"
"crs_users.Role,"
"crs_courses.DegCod"
" FROM crs_users,"
"crs_courses,"
"deg_degrees"
" WHERE crs_users.UsrCod=%ld"
" AND crs_users.CrsCod=crs_courses.CrsCod"
" AND crs_courses.DegCod=deg_degrees.DegCod"
" ORDER BY deg_degrees.ShortName,"
"crs_courses.ShortName",
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_CreateTmpTable ("CREATE TEMPORARY TABLE IF NOT EXISTS my_courses_tmp"
" (CrsCod INT NOT NULL,"
"Role TINYINT NOT NULL,"
"DegCod INT NOT NULL,"
"UNIQUE INDEX(CrsCod,Role,DegCod)) ENGINE=MEMORY"
" SELECT crs_users.CrsCod,"
"crs_users.Role,"
"crs_courses.DegCod"
" FROM crs_users,"
"crs_courses,"
"deg_degrees"
" WHERE crs_users.UsrCod=%ld"
" AND crs_users.CrsCod=crs_courses.CrsCod"
" AND crs_courses.DegCod=deg_degrees.DegCod"
" ORDER BY deg_degrees.ShortName,"
"crs_courses.ShortName",
Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
@ -118,8 +117,7 @@ unsigned Enr_DB_GetMyCourses (MYSQL_RES **mysql_res)
void Enr_DB_DropTmpTableMyCourses (void)
{
DB_Query ("can not remove temporary table",
"DROP TEMPORARY TABLE IF EXISTS my_courses_tmp");
DB_DropTmpTable ("my_courses_tmp");
}
/*****************************************************************************/
@ -205,19 +203,17 @@ bool Enr_DB_CheckIfUsrSharesAnyOfMyCrsWithDifferentRole (long UsrCod)
Enr_GetMyCourses ();
/* Remove temporary table if exists */
DB_Query ("can not remove temporary tables",
"DROP TEMPORARY TABLE IF EXISTS usr_courses_tmp");
DB_DropTmpTable ("usr_courses_tmp");
/* Create temporary table with all user's courses for a role */
DB_Query ("can not create temporary table",
"CREATE TEMPORARY TABLE IF NOT EXISTS usr_courses_tmp "
"(CrsCod INT NOT NULL,Role TINYINT NOT NULL,"
"UNIQUE INDEX(CrsCod,Role)) ENGINE=MEMORY"
" SELECT CrsCod,"
"Role"
" FROM crs_users"
" WHERE UsrCod=%ld",
UsrCod);
DB_CreateTmpTable ("CREATE TEMPORARY TABLE IF NOT EXISTS usr_courses_tmp "
"(CrsCod INT NOT NULL,Role TINYINT NOT NULL,"
"UNIQUE INDEX(CrsCod,Role)) ENGINE=MEMORY"
" SELECT CrsCod,"
"Role"
" FROM crs_users"
" WHERE UsrCod=%ld",
UsrCod);
/* Get if a user shares any course with me from database */
UsrSharesAnyOfMyCrsWithDifferentRole =
@ -230,8 +226,7 @@ bool Enr_DB_CheckIfUsrSharesAnyOfMyCrsWithDifferentRole (long UsrCod)
" AND my_courses_tmp.Role<>usr_courses_tmp.Role)");
/* Remove temporary table if exists */
DB_Query ("can not remove temporary tables",
"DROP TEMPORARY TABLE IF EXISTS usr_courses_tmp");
DB_DropTmpTable ("usr_courses_tmp");
return UsrSharesAnyOfMyCrsWithDifferentRole;
}
@ -381,8 +376,7 @@ unsigned Enr_DB_GetNumUsrsInCrssOfAUsr (long UsrCod,Rol_Role_t UsrRole,
// The temporary table achieves speedup from ~2s to few ms
/***** Remove temporary table if exists *****/
DB_Query ("can not remove temporary tables",
"DROP TEMPORARY TABLE IF EXISTS usr_courses_tmp");
DB_DropTmpTable ("usr_courses_tmp");
/***** Create temporary table with all user's courses
as student/non-editing teacher/teacher *****/
@ -405,15 +399,15 @@ unsigned Enr_DB_GetNumUsrsInCrssOfAUsr (long UsrCod,Rol_Role_t UsrRole,
Err_WrongRoleExit ();
break;
}
DB_Query ("can not create temporary table",
"CREATE TEMPORARY TABLE IF NOT EXISTS usr_courses_tmp"
" (CrsCod INT NOT NULL,UNIQUE INDEX (CrsCod))"
" ENGINE=MEMORY"
" SELECT CrsCod"
" FROM crs_users"
" WHERE UsrCod=%ld"
"%s",
UsrCod,SubQueryRole);
DB_CreateTmpTable ("CREATE TEMPORARY TABLE IF NOT EXISTS usr_courses_tmp"
" (CrsCod INT NOT NULL,UNIQUE INDEX (CrsCod))"
" ENGINE=MEMORY"
" SELECT CrsCod"
" FROM crs_users"
" WHERE UsrCod=%ld"
"%s",
UsrCod,
SubQueryRole);
/***** Get the number of students/teachers in a course from database ******/
OthersRolesStr[0] = '\0';
@ -437,8 +431,7 @@ unsigned Enr_DB_GetNumUsrsInCrssOfAUsr (long UsrCod,Rol_Role_t UsrRole,
OthersRolesStr);
/***** Remove temporary table *****/
DB_Query ("can not remove temporary tables",
"DROP TEMPORARY TABLE IF EXISTS usr_courses_tmp");
DB_DropTmpTable ("usr_courses_tmp");
return NumUsrs;
}

View File

@ -693,22 +693,20 @@ void Fol_DB_RemoveUsrFromUsrFollow (long UsrCod)
void Fol_DB_CreateTmpTableMeAndUsrsIFollow (void)
{
DB_Query ("can not create temporary table",
"CREATE TEMPORARY TABLE fol_tmp_me_and_followed "
"(UsrCod INT NOT NULL,"
"UNIQUE INDEX(UsrCod))"
" ENGINE=MEMORY"
" SELECT %ld AS UsrCod" // Me
" UNION"
" SELECT FollowedCod AS UsrCod" // Users I follow
" FROM usr_follow"
" WHERE FollowerCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_CreateTmpTable ("CREATE TEMPORARY TABLE fol_tmp_me_and_followed "
"(UsrCod INT NOT NULL,"
"UNIQUE INDEX(UsrCod))"
" ENGINE=MEMORY"
" SELECT %ld AS UsrCod" // Me
" UNION"
" SELECT FollowedCod AS UsrCod" // Users I follow
" FROM usr_follow"
" WHERE FollowerCod=%ld",
Gbl.Usrs.Me.UsrDat.UsrCod,
Gbl.Usrs.Me.UsrDat.UsrCod);
}
void Fol_DB_DropTmpTableMeAndUsrsIFollow (void)
{
DB_Query ("can not remove temporary table",
"DROP TEMPORARY TABLE IF EXISTS fol_tmp_me_and_followed");
DB_DropTmpTable ("fol_tmp_me_and_followed");
}

View File

@ -307,17 +307,15 @@ void Mai_DB_RemoveExpiredPendingEmails (void)
void Mai_DB_CreateTmpTables (void)
{
DB_Query ("can not create temporary table",
"CREATE TEMPORARY TABLE T1 ENGINE=MEMORY"
" SELECT SUBSTRING_INDEX(E_mail,'@',-1) AS Domain,"
"COUNT(*) as N"
" FROM usr_emails"
" GROUP BY Domain");
DB_CreateTmpTable ("CREATE TEMPORARY TABLE T1 ENGINE=MEMORY"
" SELECT SUBSTRING_INDEX(E_mail,'@',-1) AS Domain,"
"COUNT(*) as N"
" FROM usr_emails"
" GROUP BY Domain");
DB_Query ("can not create temporary table",
"CREATE TEMPORARY TABLE T2 ENGINE=MEMORY"
" SELECT *"
" FROM T1");
DB_CreateTmpTable ("CREATE TEMPORARY TABLE T2 ENGINE=MEMORY"
" SELECT *"
" FROM T1");
}
/*****************************************************************************/
@ -457,7 +455,6 @@ void Mai_DB_RemoveMailDomain (long MaiCod)
void Mai_DB_RemoveTmpTables (void)
{
DB_Query ("can not remove temporary tables",
"DROP TEMPORARY TABLE IF EXISTS T1,"
"T2");
DB_DropTmpTable ("T1");
DB_DropTmpTable ("T2");
}

View File

@ -76,13 +76,12 @@ void Tag_DB_AddTagToQst (long QstCod,long TagCod,unsigned TagInd)
void Tag_DB_CreateTmpTableQuestionsWithTag (long TagCod)
{
DB_Query ("can not create temporary table",
"CREATE TEMPORARY TABLE tst_question_tags_tmp"
" ENGINE=MEMORY"
" SELECT QstCod"
" FROM tst_question_tags"
" WHERE TagCod=%ld",
TagCod);
DB_CreateTmpTable ("CREATE TEMPORARY TABLE tst_question_tags_tmp"
" ENGINE=MEMORY"
" SELECT QstCod"
" FROM tst_question_tags"
" WHERE TagCod=%ld",
TagCod);
}
/*****************************************************************************/
@ -92,8 +91,7 @@ void Tag_DB_CreateTmpTableQuestionsWithTag (long TagCod)
void Tag_DB_DropTmpTableQuestionsWithTag (void)
{
DB_Query ("can not remove temporary table",
"DROP TEMPORARY TABLE IF EXISTS tst_question_tags_tmp");
DB_DropTmpTable ("tst_question_tags_tmp");
}
/*****************************************************************************/

View File

@ -45,7 +45,7 @@ mysql> SHOW TABLES LIKE 'tml_%';
*Numbers are got from swad.ugr.es on may 2021
____tml_pubs___ _tml_comments
_tml_pubs______ _tml_comments
| | | |
| Publication p |---------->| Comment c |-----+
| (comment) | | (to note 2) | |
@ -61,35 +61,35 @@ mysql> SHOW TABLES LIKE 'tml_%';
| | (4855) | |
|Publication i+3|-- | |
|(original note)| \ | |
|_______________| \ ___tml_notes___ | | _calls_for_exams
|_______________| \ _tml_notes_____ | | _cfe_exams_____
| | \ | | | | | |
|Publication i+2|-- ---->| Note n |<-+ | | Call for exam | (5581)
|(original note)| \ |(exam announc.)|-(2622)->|_______________|
|_______________| \ |_______________| 11% ____files____
| | \ | | | | |
|Publication i+1|-- ---->| Note n-1 |-(64)--->| Public file | (1497132)
|(original note)| \ | (public file) | <1% |_____________|
|_______________| \ |_______________| | _notices_
| | \ | | | | |
| Publication i |-- ---->| Note n-2 |-(17078)>| Notice | (14984)
|(original note)| \ | (notice) | 72% |_________|
|_______________| \ |_______________| | __tml_posts__
| | \ | | | | |
· ... · ---->| Note n-3 |-(3533)->| Post s |
· ... · | (tl. post) | 15% | |
|_______________| |_______________| | |_____________|
| | | | | | |
| Publication 3 | · ... · | · ... · (3533)
| (shared note) |--- · ... · | · ... ·
|_______________| \ |_______________| | |_____________|
| | \ | | | | |
| Publication 2 | ---->| Note 2 |<---+ | Post 1 |
|(original note)|--------->| (tl. post) |-------->| |
|_______________| |_______________| |_____________|
| | | | _forum_post_
| Publication 1 |--------->| Note 1 | | |
|(original note)| | (forum post) |-(276)-->| Forum post | (66226)
|_______________| |_______________| 1% |____________|
|_______________| \ |_______________| 11% _brw_files_____
| | \ | | | | |
|Publication i+1|-- ---->| Note n-1 |-(64)--->| Public file | (1497132)
|(original note)| \ | (public file) | <1% |_______________|
|_______________| \ |_______________| | _not_notices___
| | \ | | | | |
| Publication i |-- ---->| Note n-2 |-(17078)>| Notice | (14984)
|(original note)| \ | (notice) | 72% |_______________|
|_______________| \ |_______________| | _tml_posts_____
| | \ | | | | |
· ... · ---->| Note n-3 |-(3533)->| Post s |
· ... · | (tl. post) | 15% | |
|_______________| |_______________| | |_______________|
| | | | | | |
| Publication 3 | · ... · | · ... · (3533)
| (shared note) |--- · ... · | · ... ·
|_______________| \ |_______________| | |_______________|
| | \ | | | | |
| Publication 2 | ---->| Note 2 |<---+ | Post 1 |
|(original note)|--------->| (tl. post) |-------->| |
|_______________| |_______________| |_______________|
| | | | _for_posts_____
| Publication 1 |--------->| Note 1 | | |
|(original note)| | (forum post) |-(276)-->| Forum post | (66226)
|_______________| |_______________| 1% |_______________|
(29435) (23573)
A note can be:

View File

@ -397,55 +397,34 @@ unsigned Tml_DB_GetNumNotesAndUsrsTotal (MYSQL_RES **mysql_res)
/******* Create temporary tables used to not get notes already shown *********/
/*****************************************************************************/
void Tml_DB_CreateTmpTableJustRetrievedNotes (void)
void Tml_DB_CreateTmpTableTimeline (Tml_WhatToGet_t WhatToGet)
{
DB_Query ("can not create temporary table",
"CREATE TEMPORARY TABLE tml_tmp_just_retrieved_notes "
"(NotCod BIGINT NOT NULL,UNIQUE INDEX(NotCod))"
" ENGINE=MEMORY");
}
void Tml_DB_CreateTmpTableVisibleTimeline (void)
{
DB_Query ("can not create temporary table",
"CREATE TEMPORARY TABLE tml_tmp_visible_timeline "
"(NotCod BIGINT NOT NULL,UNIQUE INDEX(NotCod))"
" ENGINE=MEMORY"
" SELECT NotCod"
" FROM tml_timelines"
" WHERE SessionId='%s'",
Gbl.Session.Id);
switch (WhatToGet)
{
case Tml_GET_OLD_PUBS:
DB_CreateTmpTable ("CREATE TEMPORARY TABLE tml_tmp_timeline "
"(NotCod BIGINT NOT NULL,UNIQUE INDEX(NotCod))"
" ENGINE=MEMORY"
" SELECT NotCod"
" FROM tml_timelines"
" WHERE SessionId='%s'",
Gbl.Session.Id);
break;
case Tml_GET_NEW_PUBS:
case Tml_GET_REC_PUBS:
default:
DB_CreateTmpTable ("CREATE TEMPORARY TABLE tml_tmp_timeline "
"(NotCod BIGINT NOT NULL,UNIQUE INDEX(NotCod))"
" ENGINE=MEMORY");
break;
}
}
/*****************************************************************************/
/**** Insert note in temporary tables used to not get notes already shown ****/
/**** Insert note in temporary table used to not get notes already shown *****/
/*****************************************************************************/
void Tml_DB_InsertNoteInJustRetrievedNotes (long NotCod)
{
/* Insert note in temporary table with just retrieved notes.
This table will be used to not get notes already shown */
DB_QueryINSERT ("can not store note code",
"INSERT IGNORE INTO tml_tmp_just_retrieved_notes"
" SET NotCod=%ld",
NotCod);
}
void Tml_DB_InsertNoteInVisibleTimeline (long NotCod)
{
/* Insert note in temporary table with visible timeline.
This table will be used to not get notes already shown */
DB_QueryINSERT ("can not store note code",
"INSERT IGNORE INTO tml_tmp_visible_timeline"
" SET NotCod=%ld",
NotCod);
}
/*****************************************************************************/
/****** Add just retrieved notes to current timeline for this session ********/
/*****************************************************************************/
void Tml_DB_AddNotesJustRetrievedToVisibleTimelineOfSession (void)
void Tml_DB_InsertNoteInTimeline (long NotCod)
{
/* tml_timelines contains the distinct notes in timeline of each open session:
mysql> SELECT SessionId,COUNT(*) FROM tml_timelines GROUP BY SessionId;
@ -465,31 +444,29 @@ mysql> SELECT SessionId,COUNT(*) FROM tml_timelines GROUP BY SessionId;
+---------------------------------------------+----------+
10 rows in set (0,01 sec)
*/
DB_QueryINSERT ("can not insert notes in timeline",
/* Insert note in temporary table with visible timeline.
This table will be used to not get notes already shown */
DB_QueryINSERT ("can not insert note in timeline",
"INSERT IGNORE INTO tml_tmp_timeline"
" SET NotCod=%ld",
NotCod);
DB_QueryINSERT ("can not insert note in timeline",
"INSERT IGNORE INTO tml_timelines"
" (SessionId,NotCod)"
" SELECT '%s',"
"NotCod"
" FROM tml_tmp_just_retrieved_notes",
Gbl.Session.Id);
" VALUES"
" ('%s',%ld)",
Gbl.Session.Id,
NotCod);
}
/*****************************************************************************/
/******** Drop temporary tables used to not get notes already shown **********/
/********** Drop temporary table with all notes visible in timeline **********/
/*****************************************************************************/
void Tml_DB_DropTmpTableJustRetrievedNotes (void)
void Tml_DB_DropTmpTableTimeline (void)
{
/***** Drop temporary table with notes just retrieved *****/
DB_Query ("can not remove temporary table",
"DROP TEMPORARY TABLE IF EXISTS tml_tmp_just_retrieved_notes");
}
void Tml_DB_DropTmpTableVisibleTimeline (void)
{
/***** Drop temporary table with all notes visible in timeline *****/
DB_Query ("can not remove temporary table",
"DROP TEMPORARY TABLE IF EXISTS tml_tmp_visible_timeline");
DB_DropTmpTable ("tml_tmp_timeline");
}
/*****************************************************************************/
@ -918,21 +895,13 @@ void Tml_DB_CreateSubQueryPublishers (Tml_Usr_UsrOrGbl_t UsrOrGbl,Usr_Who_t Who,
/********* Create subquery to get only notes not present in timeline *********/
/*****************************************************************************/
void Tml_DB_CreateSubQueryAlreadyExists (Tml_WhatToGet_t WhatToGet,
char AlreadyExists[Tml_Pub_MAX_BYTES_SUBQUERY + 1])
void Tml_DB_CreateSubQueryAlreadyExists (char AlreadyExists[Tml_Pub_MAX_BYTES_SUBQUERY + 1])
{
static const char *Table[Tml_NUM_WHAT_TO_GET] =
{
[Tml_GET_NEW_PUBS] = "tml_tmp_just_retrieved_notes", // Avoid notes just retrieved
[Tml_GET_REC_PUBS] = "tml_tmp_just_retrieved_notes", // Avoid notes just retrieved
[Tml_GET_OLD_PUBS] = "tml_tmp_visible_timeline", // Avoid notes already shown
};
snprintf (AlreadyExists,Tml_Pub_MAX_BYTES_SUBQUERY + 1,
Str_Copy (AlreadyExists,
" tml_pubs.NotCod NOT IN"
" (SELECT NotCod"
" FROM %s)",
Table[WhatToGet]);
" FROM tml_tmp_timeline)",
Tml_Pub_MAX_BYTES_SUBQUERY);
}
/*****************************************************************************/

View File

@ -57,13 +57,9 @@ unsigned Tml_DB_GetNumNotesAndUsrsByType (MYSQL_RES **mysql_res,
Tml_Not_Type_t NoteType);
unsigned Tml_DB_GetNumNotesAndUsrsTotal (MYSQL_RES **mysql_res);
void Tml_DB_CreateTmpTableJustRetrievedNotes (void);
void Tml_DB_CreateTmpTableVisibleTimeline (void);
void Tml_DB_InsertNoteInJustRetrievedNotes (long NotCod);
void Tml_DB_InsertNoteInVisibleTimeline (long NotCod);
void Tml_DB_AddNotesJustRetrievedToVisibleTimelineOfSession (void);
void Tml_DB_DropTmpTableJustRetrievedNotes (void);
void Tml_DB_DropTmpTableVisibleTimeline (void);
void Tml_DB_CreateTmpTableTimeline (Tml_WhatToGet_t WhatToGet);
void Tml_DB_InsertNoteInTimeline (long NotCod);
void Tml_DB_DropTmpTableTimeline (void);
void Tml_DB_ClearOldTimelinesNotesFromDB (void);
void Tml_DB_ClearTimelineNotesOfSessionFromDB (void);
@ -100,8 +96,7 @@ void Tml_DB_RemoveAllCommsMadeBy (long UsrCod);
void Tml_DB_CreateSubQueryPublishers (Tml_Usr_UsrOrGbl_t UsrOrGbl,Usr_Who_t Who,
char **Table,
char SubQuery[Tml_Pub_MAX_BYTES_SUBQUERY + 1]);
void Tml_DB_CreateSubQueryAlreadyExists (Tml_WhatToGet_t WhatToGet,
char AlreadyExists[Tml_Pub_MAX_BYTES_SUBQUERY + 1]);
void Tml_DB_CreateSubQueryAlreadyExists (char AlreadyExists[Tml_Pub_MAX_BYTES_SUBQUERY + 1]);
void Tml_DB_CreateSubQueryRangeBottom (long Bottom,
char SubQuery[Tml_Pub_MAX_BYTES_SUBQUERY + 1]);
void Tml_DB_CreateSubQueryRangeTop (long Top,

View File

@ -1172,8 +1172,7 @@ static void Tml_Not_RemoveNoteMediaAndDBEntries (struct Tml_Not_Note *Not)
/***** Mark possible notifications on the publications
of this note as removed *****/
PubCod = Tml_DB_GetPubCodOfOriginalNote (Not->NotCod);
if (PubCod > 0)
if ((PubCod = Tml_DB_GetPubCodOfOriginalNote (Not->NotCod)) > 0)
{
Ntf_DB_MarkNotifAsRemoved (Ntf_EVENT_TML_FAV ,PubCod);
Ntf_DB_MarkNotifAsRemoved (Ntf_EVENT_TML_SHARE ,PubCod);

View File

@ -96,13 +96,8 @@ void Tml_Pub_GetListPubsToShowInTimeline (struct Tml_Timeline *Timeline)
if (Timeline->WhatToGet == Tml_GET_REC_PUBS)
Tml_DB_ClearTimelineNotesOfSessionFromDB ();
/***** Create temporary tables *****/
/* Create temporary table with notes just retrieved */
Tml_DB_CreateTmpTableJustRetrievedNotes ();
/* Create temporary table with all notes visible in timeline */
if (Timeline->WhatToGet == Tml_GET_OLD_PUBS)
Tml_DB_CreateTmpTableVisibleTimeline ();
/***** Create temporary table with all notes visible in timeline *****/
Tml_DB_CreateTmpTableTimeline (Timeline->WhatToGet);
/***** Create subqueries *****/
/* Create subquery with potential publishers */
@ -111,8 +106,7 @@ void Tml_Pub_GetListPubsToShowInTimeline (struct Tml_Timeline *Timeline)
SubQueries.Publishers.SubQuery);
/* Create subquery to get only notes not present in timeline */
Tml_DB_CreateSubQueryAlreadyExists (Timeline->WhatToGet,
SubQueries.AlreadyExists);
Tml_DB_CreateSubQueryAlreadyExists (SubQueries.AlreadyExists);
/* Create subquery with bottom range of publications to get from tml_pubs.
Bottom pub. code remains unchanged in all iterations of the loop. */
@ -179,11 +173,9 @@ void Tml_Pub_GetListPubsToShowInTimeline (struct Tml_Timeline *Timeline)
if (Pub == NULL) // Nothing got ==> abort loop
break; // Last publication
/* Insert note in temporary tables with just retrieved notes.
/* Insert note in temporary tables with visible notes.
These tables will be used to not get notes already shown */
Tml_DB_InsertNoteInJustRetrievedNotes (Pub->NotCod);
if (Timeline->WhatToGet == Tml_GET_OLD_PUBS) // Get only old publications
Tml_DB_InsertNoteInVisibleTimeline (Pub->NotCod);
Tml_DB_InsertNoteInTimeline (Pub->NotCod);
/* Narrow the range for the next iteration */
RangePubsToGet.Top = Pub->PubCod;
@ -193,14 +185,9 @@ void Tml_Pub_GetListPubsToShowInTimeline (struct Tml_Timeline *Timeline)
into session for next refresh *****/
Tml_Pub_UpdateFirstLastPubCodesIntoSession (Timeline);
/***** Add notes just retrieved to visible timeline for this session *****/
Tml_DB_AddNotesJustRetrievedToVisibleTimelineOfSession ();
/***** Drop temporary tables *****/
/* Drop temporary tables with notes already retrieved */
Tml_DB_DropTmpTableJustRetrievedNotes ();
if (Timeline->WhatToGet == Tml_GET_OLD_PUBS) // Get only old publications
Tml_DB_DropTmpTableVisibleTimeline ();
/* Drop temporary table with visible notes in timeline */
Tml_DB_DropTmpTableTimeline ();
/* Drop temporary table with me and users I follow */
if (Timeline->UsrOrGbl == Tml_Usr_TIMELINE_GBL && // Show the global timeline

View File

@ -121,7 +121,7 @@ static void Tml_Sha_ShaNote (struct Tml_Not_Note *Not)
/***** Share (publish note in timeline) *****/
Pub.NotCod = Not->NotCod;
Pub.PublisherCod = Gbl.Usrs.Me.UsrDat.UsrCod;
Pub.Type = Tml_Pub_SHARED_NOTE;
Pub.Type = Tml_Pub_SHARED_NOTE;
Tml_Pub_PublishPubInTimeline (&Pub); // Set Pub.PubCod
/***** Update number of times this note is shared *****/
@ -129,8 +129,7 @@ static void Tml_Sha_ShaNote (struct Tml_Not_Note *Not)
/***** Create notification about shared post
for the author of the post *****/
OriginalPubCod = Tml_DB_GetPubCodOfOriginalNote (Not->NotCod);
if (OriginalPubCod > 0)
if ((OriginalPubCod = Tml_DB_GetPubCodOfOriginalNote (Not->NotCod)) > 0)
Tml_Ntf_CreateNotifToAuthor (Not->UsrCod,OriginalPubCod,Ntf_EVENT_TML_SHARE);
}
@ -179,7 +178,6 @@ static void Tml_Sha_UnsNote (struct Tml_Not_Note *Not)
Not->NumShared = Tml_DB_GetNumSharers (Not->NotCod,Not->UsrCod);
/***** Mark possible notifications on this note as removed *****/
OriginalPubCod = Tml_DB_GetPubCodOfOriginalNote (Not->NotCod);
if (OriginalPubCod > 0)
if ((OriginalPubCod = Tml_DB_GetPubCodOfOriginalNote (Not->NotCod)) > 0)
Ntf_DB_MarkNotifAsRemoved (Ntf_EVENT_TML_SHARE,OriginalPubCod);
}

View File

@ -961,7 +961,7 @@ void Usr_DB_BuildQueryToSearchListUsrs (Rol_Role_t Role,char **Query)
"usr_data.CtyCod," // row[ 9]
"usr_data.InsCod"; // row[10]
static const char *OrderBySubQuery =
"candidate_users.UsrCod=usr_data.UsrCod"
"usr_candidate_users.UsrCod=usr_data.UsrCod"
" ORDER BY usr_data.Surname1,"
"usr_data.Surname2,"
"usr_data.FirstName,"
@ -980,7 +980,7 @@ void Usr_DB_BuildQueryToSearchListUsrs (Rol_Role_t Role,char **Query)
/* Search users from the whole platform */
DB_BuildQuery (Query,
"SELECT %s"
" FROM candidate_users,usr_data"
" FROM usr_candidate_users,usr_data"
" WHERE %s",
QueryFields,
OrderBySubQuery);
@ -989,14 +989,14 @@ void Usr_DB_BuildQueryToSearchListUsrs (Rol_Role_t Role,char **Query)
/* Search users in courses from the current country */
DB_BuildQuery (Query,
"SELECT %s"
" FROM candidate_users,"
" FROM usr_candidate_users,"
"crs_users,"
"crs_courses,"
"deg_degrees,"
"ctr_centers,"
"ins_instits,"
"usr_data"
" WHERE candidate_users.UsrCod=crs_users.UsrCod"
" WHERE usr_candidate_users.UsrCod=crs_users.UsrCod"
" AND crs_users.CrsCod=crs_courses.CrsCod"
" AND crs_courses.DegCod=deg_degrees.DegCod"
" AND deg_degrees.CtrCod=ctr_centers.CtrCod"
@ -1011,13 +1011,13 @@ void Usr_DB_BuildQueryToSearchListUsrs (Rol_Role_t Role,char **Query)
/* Search users in courses from the current institution */
DB_BuildQuery (Query,
"SELECT %s"
" FROM candidate_users,"
" FROM usr_candidate_users,"
"crs_users,"
"crs_courses,"
"deg_degrees,"
"ctr_centers,"
"usr_data"
" WHERE candidate_users.UsrCod=crs_users.UsrCod"
" WHERE usr_candidate_users.UsrCod=crs_users.UsrCod"
" AND crs_users.CrsCod=crs_courses.CrsCod"
" AND crs_courses.DegCod=deg_degrees.DegCod"
" AND deg_degrees.CtrCod=ctr_centers.CtrCod"
@ -1031,12 +1031,12 @@ void Usr_DB_BuildQueryToSearchListUsrs (Rol_Role_t Role,char **Query)
/* Search users in courses from the current center */
DB_BuildQuery (Query,
"SELECT %s"
" FROM candidate_users,"
" FROM usr_candidate_users,"
"crs_users,"
"crs_courses,"
"deg_degrees,"
" usr_data"
" WHERE candidate_users.UsrCod=crs_users.UsrCod"
" WHERE usr_candidate_users.UsrCod=crs_users.UsrCod"
" AND crs_users.CrsCod=crs_courses.CrsCod"
" AND crs_courses.DegCod=deg_degrees.DegCod"
" AND deg_degrees.CtrCod=%ld"
@ -1049,11 +1049,11 @@ void Usr_DB_BuildQueryToSearchListUsrs (Rol_Role_t Role,char **Query)
/* Search users in courses from the current degree */
DB_BuildQuery (Query,
"SELECT %s"
" FROM candidate_users,"
" FROM usr_candidate_users,"
"crs_users,"
"crs_courses,"
"usr_data"
" WHERE candidate_users.UsrCod=crs_users.UsrCod"
" WHERE usr_candidate_users.UsrCod=crs_users.UsrCod"
" AND crs_users.CrsCod=crs_courses.CrsCod"
" AND crs_courses.DegCod=%ld"
" AND %s",
@ -1067,10 +1067,10 @@ void Usr_DB_BuildQueryToSearchListUsrs (Rol_Role_t Role,char **Query)
"SELECT %s,"
"crs_users.Role," // row[11]
"crs_users.Accepted" // row[12]
" FROM candidate_users,"
" FROM usr_candidate_users,"
"crs_users,"
"usr_data"
" WHERE candidate_users.UsrCod=crs_users.UsrCod"
" WHERE usr_candidate_users.UsrCod=crs_users.UsrCod"
" AND crs_users.CrsCod=%ld"
" AND %s",
QueryFields,
@ -1086,9 +1086,9 @@ void Usr_DB_BuildQueryToSearchListUsrs (Rol_Role_t Role,char **Query)
/* Search users with no courses */
DB_BuildQuery (Query,
"SELECT %s"
" FROM candidate_users,"
" FROM usr_candidate_users,"
"usr_data"
" WHERE candidate_users.UsrCod NOT IN"
" WHERE usr_candidate_users.UsrCod NOT IN"
" (SELECT UsrCod"
" FROM crs_users)"
" AND %s",
@ -1125,10 +1125,10 @@ void Usr_DB_BuildQueryToSearchListUsrs (Rol_Role_t Role,char **Query)
/* Search users in courses from the whole platform */
DB_BuildQuery (Query,
"SELECT %s"
" FROM candidate_users,"
" FROM usr_candidate_users,"
"crs_users,"
"usr_data"
" WHERE candidate_users.UsrCod=crs_users.UsrCod"
" WHERE usr_candidate_users.UsrCod=crs_users.UsrCod"
"%s"
" AND %s",
QueryFields,
@ -1139,14 +1139,14 @@ void Usr_DB_BuildQueryToSearchListUsrs (Rol_Role_t Role,char **Query)
/* Search users in courses from the current country */
DB_BuildQuery (Query,
"SELECT %s"
" FROM candidate_users,"
" FROM usr_candidate_users,"
"crs_users,"
"crs_courses,"
"deg_degrees,"
"ctr_centers,"
"ins_instits,"
"usr_data"
" WHERE candidate_users.UsrCod=crs_users.UsrCod"
" WHERE usr_candidate_users.UsrCod=crs_users.UsrCod"
"%s"
" AND crs_users.CrsCod=crs_courses.CrsCod"
" AND crs_courses.DegCod=deg_degrees.DegCod"
@ -1163,13 +1163,13 @@ void Usr_DB_BuildQueryToSearchListUsrs (Rol_Role_t Role,char **Query)
/* Search users in courses from the current institution */
DB_BuildQuery (Query,
"SELECT %s"
" FROM candidate_users,"
" FROM usr_candidate_users,"
"crs_users,"
"crs_courses,"
"deg_degrees,"
"ctr_centers,"
"usr_data"
" WHERE candidate_users.UsrCod=crs_users.UsrCod"
" WHERE usr_candidate_users.UsrCod=crs_users.UsrCod"
"%s"
" AND crs_users.CrsCod=crs_courses.CrsCod"
" AND crs_courses.DegCod=deg_degrees.DegCod"
@ -1185,12 +1185,12 @@ void Usr_DB_BuildQueryToSearchListUsrs (Rol_Role_t Role,char **Query)
/* Search users in courses from the current center */
DB_BuildQuery (Query,
"SELECT %s"
" FROM candidate_users,"
" FROM usr_candidate_users,"
"crs_users,"
"crs_courses,"
"deg_degrees,"
"usr_data"
" WHERE candidate_users.UsrCod=crs_users.UsrCod"
" WHERE usr_candidate_users.UsrCod=crs_users.UsrCod"
"%s"
" AND crs_users.CrsCod=crs_courses.CrsCod"
" AND crs_courses.DegCod=deg_degrees.DegCod"
@ -1205,11 +1205,11 @@ void Usr_DB_BuildQueryToSearchListUsrs (Rol_Role_t Role,char **Query)
/* Search users in courses from the current degree */
DB_BuildQuery (Query,
"SELECT %s"
" FROM candidate_users,"
" FROM usr_candidate_users,"
"crs_users,"
"crs_courses,"
"usr_data"
" WHERE candidate_users.UsrCod=crs_users.UsrCod"
" WHERE usr_candidate_users.UsrCod=crs_users.UsrCod"
"%s"
" AND crs_users.CrsCod=crs_courses.CrsCod"
" AND crs_courses.DegCod=%ld"
@ -1225,10 +1225,10 @@ void Usr_DB_BuildQueryToSearchListUsrs (Rol_Role_t Role,char **Query)
"SELECT %s,"
"crs_users.Role,"
"crs_users.Accepted"
" FROM candidate_users,"
" FROM usr_candidate_users,"
"crs_users,"
"usr_data"
" WHERE candidate_users.UsrCod=crs_users.UsrCod"
" WHERE usr_candidate_users.UsrCod=crs_users.UsrCod"
"%s"
" AND crs_users.CrsCod=%ld"
" AND %s",
@ -1410,13 +1410,12 @@ void Usr_DB_CreateTmpTableAndSearchCandidateUsrs (const char SearchQuery[Sch_MAX
- Searching for names is made in the whole platform
and stored in this table.
*/
DB_Query ("can not create temporary table",
"CREATE TEMPORARY TABLE candidate_users"
" (UsrCod INT NOT NULL,UNIQUE INDEX(UsrCod)) ENGINE=MEMORY"
" SELECT UsrCod"
" FROM usr_data"
" WHERE %s",
SearchQuery);
DB_CreateTmpTable ("CREATE TEMPORARY TABLE usr_candidate_users"
" (UsrCod INT NOT NULL,UNIQUE INDEX(UsrCod)) ENGINE=MEMORY"
" SELECT UsrCod"
" FROM usr_data"
" WHERE %s",
SearchQuery);
}
/*****************************************************************************/
@ -1425,8 +1424,7 @@ void Usr_DB_CreateTmpTableAndSearchCandidateUsrs (const char SearchQuery[Sch_MAX
void Usr_DB_DropTmpTableWithCandidateUsrs (void)
{
DB_Query ("can not remove temporary table",
"DROP TEMPORARY TABLE IF EXISTS candidate_users");
DB_DropTmpTable ("usr_candidate_users");
}
/*****************************************************************************/