Fossil SCM
Remove some extraneous joins and apply a missing forum status filter rule. This seems to filter as desired.
Commit
ee392e1366cc05b6734b009cc0ea3d001803ce207b8d19c28fc771ce34d9e2ef
Parent
d1fb4a49bb3418d…
1 file changed
+19
-16
+19
-16
| --- src/forum.c | ||
| +++ src/forum.c | ||
| @@ -2499,54 +2499,57 @@ | ||
| 2499 | 2499 | iStatusTagId, !!zStatusFilter, zStatusFilter |
| 2500 | 2500 | ); |
| 2501 | 2501 | if( zStatusFilter ){ |
| 2502 | 2502 | const int bIsDflt = |
| 2503 | 2503 | 0==fossil_strcmp(pFstat->aStatus[0].zValue, zStatusFilter); |
| 2504 | - const int bIsKnown =bIsDflt | |
| 2505 | - ? 1 | |
| 2506 | - : db_int(0, "SELECT 1 FROM forumstatus WHERE value=%Q", | |
| 2507 | - zStatusFilter); | |
| 2508 | 2504 | db_multi_exec( |
| 2505 | + "WITH stati(val) AS (SELECT value FROM forumstatus)\n" | |
| 2509 | 2506 | "INSERT INTO trootid\n" |
| 2510 | 2507 | /* Rules: |
| 2511 | 2508 | |
| 2512 | 2509 | (1) Filter on status=$zStatusFilter |
| 2513 | 2510 | (2) If $zStatusFilter==default status then also include |
| 2514 | 2511 | any posts with no status tag. |
| 2515 | - (3) If no matching tag is found, assume a tag with the value | |
| 2516 | - of the first (default) status. | |
| 2512 | + (3) If no status tag is found for a given post, assume a tag | |
| 2513 | + with the value of the first (default) status. | |
| 2514 | + (4) If a status value is found which is not in | |
| 2515 | + [forumstatus] then treat it as if it were the default | |
| 2516 | + value. | |
| 2517 | 2517 | |
| 2518 | 2518 | We need to ensure that we filter only the most recent |
| 2519 | 2519 | value of each tag and count tagtype=0 (cancel) tags |
| 2520 | 2520 | properly. |
| 2521 | 2521 | */ |
| 2522 | - " SELECT fpid FROM forumpost, event\n" | |
| 2523 | - " LEFT JOIN tagxref x ON objid=rid\n" | |
| 2522 | + " SELECT fpid FROM forumpost\n" | |
| 2523 | + " LEFT JOIN tagxref x ON fpid=rid\n" | |
| 2524 | 2524 | " WHERE froot=fpid AND firt IS NULL\n" |
| 2525 | + " AND (x.tagtype IS NULL OR x.tagtype>0)\n" | |
| 2525 | 2526 | " AND (x.tagid IS NULL OR x.tagid=%d)\n" |
| 2526 | - " AND fpid=objid AND type='f'\n" | |
| 2527 | 2527 | " AND CASE\n" |
| 2528 | - " WHEN %d THEN (x.value IS NULL OR x.value=%Q)\n" /* (2,3) */ | |
| 2528 | + " WHEN %d" /*bIsDflt*/ | |
| 2529 | + " THEN (" | |
| 2530 | + " x.value IS NULL" | |
| 2531 | + " OR x.value=%Q" | |
| 2532 | + " OR x.value NOT IN stati" /* (4) */ | |
| 2533 | + " )\n" /* (2,3,4) */ | |
| 2529 | 2534 | " ELSE x.value=%Q\n" /* (1) */ |
| 2530 | 2535 | " END", |
| 2531 | 2536 | iStatusTagId, bIsDflt, zStatusFilter, zStatusFilter |
| 2532 | 2537 | ); |
| 2533 | 2538 | (void)bIsDflt; |
| 2534 | 2539 | }else{ |
| 2535 | 2540 | db_multi_exec( |
| 2536 | 2541 | "INSERT INTO trootid\n" |
| 2537 | - " SELECT fpid FROM forumpost, event\n" | |
| 2538 | - " WHERE froot=fpid AND firt IS NULL\n" | |
| 2539 | - " AND fpid=objid AND type='f'" | |
| 2542 | + " SELECT fpid FROM forumpost\n" | |
| 2543 | + " WHERE froot=fpid AND firt IS NULL" | |
| 2540 | 2544 | ); |
| 2541 | 2545 | } |
| 2542 | 2546 | }else{ |
| 2543 | 2547 | db_multi_exec( |
| 2544 | 2548 | "INSERT INTO trootid\n" |
| 2545 | - " SELECT fpid FROM forumpost, event\n" | |
| 2546 | - " WHERE froot=fpid AND firt IS NULL\n" | |
| 2547 | - " AND fpid=objid AND type='f'" | |
| 2549 | + " SELECT fpid FROM forumpost\n" | |
| 2550 | + " WHERE froot=fpid AND firt IS NULL" | |
| 2548 | 2551 | ); |
| 2549 | 2552 | } |
| 2550 | 2553 | db_prepare(&q, |
| 2551 | 2554 | "WITH thread(root,endtime,lastrid) AS (\n" |
| 2552 | 2555 | " SELECT\n" |
| 2553 | 2556 |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -2499,54 +2499,57 @@ | |
| 2499 | iStatusTagId, !!zStatusFilter, zStatusFilter |
| 2500 | ); |
| 2501 | if( zStatusFilter ){ |
| 2502 | const int bIsDflt = |
| 2503 | 0==fossil_strcmp(pFstat->aStatus[0].zValue, zStatusFilter); |
| 2504 | const int bIsKnown =bIsDflt |
| 2505 | ? 1 |
| 2506 | : db_int(0, "SELECT 1 FROM forumstatus WHERE value=%Q", |
| 2507 | zStatusFilter); |
| 2508 | db_multi_exec( |
| 2509 | "INSERT INTO trootid\n" |
| 2510 | /* Rules: |
| 2511 | |
| 2512 | (1) Filter on status=$zStatusFilter |
| 2513 | (2) If $zStatusFilter==default status then also include |
| 2514 | any posts with no status tag. |
| 2515 | (3) If no matching tag is found, assume a tag with the value |
| 2516 | of the first (default) status. |
| 2517 | |
| 2518 | We need to ensure that we filter only the most recent |
| 2519 | value of each tag and count tagtype=0 (cancel) tags |
| 2520 | properly. |
| 2521 | */ |
| 2522 | " SELECT fpid FROM forumpost, event\n" |
| 2523 | " LEFT JOIN tagxref x ON objid=rid\n" |
| 2524 | " WHERE froot=fpid AND firt IS NULL\n" |
| 2525 | " AND (x.tagid IS NULL OR x.tagid=%d)\n" |
| 2526 | " AND fpid=objid AND type='f'\n" |
| 2527 | " AND CASE\n" |
| 2528 | " WHEN %d THEN (x.value IS NULL OR x.value=%Q)\n" /* (2,3) */ |
| 2529 | " ELSE x.value=%Q\n" /* (1) */ |
| 2530 | " END", |
| 2531 | iStatusTagId, bIsDflt, zStatusFilter, zStatusFilter |
| 2532 | ); |
| 2533 | (void)bIsDflt; |
| 2534 | }else{ |
| 2535 | db_multi_exec( |
| 2536 | "INSERT INTO trootid\n" |
| 2537 | " SELECT fpid FROM forumpost, event\n" |
| 2538 | " WHERE froot=fpid AND firt IS NULL\n" |
| 2539 | " AND fpid=objid AND type='f'" |
| 2540 | ); |
| 2541 | } |
| 2542 | }else{ |
| 2543 | db_multi_exec( |
| 2544 | "INSERT INTO trootid\n" |
| 2545 | " SELECT fpid FROM forumpost, event\n" |
| 2546 | " WHERE froot=fpid AND firt IS NULL\n" |
| 2547 | " AND fpid=objid AND type='f'" |
| 2548 | ); |
| 2549 | } |
| 2550 | db_prepare(&q, |
| 2551 | "WITH thread(root,endtime,lastrid) AS (\n" |
| 2552 | " SELECT\n" |
| 2553 |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -2499,54 +2499,57 @@ | |
| 2499 | iStatusTagId, !!zStatusFilter, zStatusFilter |
| 2500 | ); |
| 2501 | if( zStatusFilter ){ |
| 2502 | const int bIsDflt = |
| 2503 | 0==fossil_strcmp(pFstat->aStatus[0].zValue, zStatusFilter); |
| 2504 | db_multi_exec( |
| 2505 | "WITH stati(val) AS (SELECT value FROM forumstatus)\n" |
| 2506 | "INSERT INTO trootid\n" |
| 2507 | /* Rules: |
| 2508 | |
| 2509 | (1) Filter on status=$zStatusFilter |
| 2510 | (2) If $zStatusFilter==default status then also include |
| 2511 | any posts with no status tag. |
| 2512 | (3) If no status tag is found for a given post, assume a tag |
| 2513 | with the value of the first (default) status. |
| 2514 | (4) If a status value is found which is not in |
| 2515 | [forumstatus] then treat it as if it were the default |
| 2516 | value. |
| 2517 | |
| 2518 | We need to ensure that we filter only the most recent |
| 2519 | value of each tag and count tagtype=0 (cancel) tags |
| 2520 | properly. |
| 2521 | */ |
| 2522 | " SELECT fpid FROM forumpost\n" |
| 2523 | " LEFT JOIN tagxref x ON fpid=rid\n" |
| 2524 | " WHERE froot=fpid AND firt IS NULL\n" |
| 2525 | " AND (x.tagtype IS NULL OR x.tagtype>0)\n" |
| 2526 | " AND (x.tagid IS NULL OR x.tagid=%d)\n" |
| 2527 | " AND CASE\n" |
| 2528 | " WHEN %d" /*bIsDflt*/ |
| 2529 | " THEN (" |
| 2530 | " x.value IS NULL" |
| 2531 | " OR x.value=%Q" |
| 2532 | " OR x.value NOT IN stati" /* (4) */ |
| 2533 | " )\n" /* (2,3,4) */ |
| 2534 | " ELSE x.value=%Q\n" /* (1) */ |
| 2535 | " END", |
| 2536 | iStatusTagId, bIsDflt, zStatusFilter, zStatusFilter |
| 2537 | ); |
| 2538 | (void)bIsDflt; |
| 2539 | }else{ |
| 2540 | db_multi_exec( |
| 2541 | "INSERT INTO trootid\n" |
| 2542 | " SELECT fpid FROM forumpost\n" |
| 2543 | " WHERE froot=fpid AND firt IS NULL" |
| 2544 | ); |
| 2545 | } |
| 2546 | }else{ |
| 2547 | db_multi_exec( |
| 2548 | "INSERT INTO trootid\n" |
| 2549 | " SELECT fpid FROM forumpost\n" |
| 2550 | " WHERE froot=fpid AND firt IS NULL" |
| 2551 | ); |
| 2552 | } |
| 2553 | db_prepare(&q, |
| 2554 | "WITH thread(root,endtime,lastrid) AS (\n" |
| 2555 | " SELECT\n" |
| 2556 |