Fossil SCM
Add the "fossil chat reindex" command. Add buttons in the /srchsetup and /setup_chat pages that will rebuild the chat FTS index.
Commit
43af043bd7e33e5a517129c797ff18edb1e66ceefd3e28a329a3aea0912bbc4a
Parent
3fe805acb6fd374…
2 files changed
+16
-1
+25
-10
+16
-1
| --- src/chat.c | ||
| +++ src/chat.c | ||
| @@ -296,10 +296,11 @@ | ||
| 296 | 296 | ** chatfts1 table and recreate/reindex it. If bForce is 0, it will |
| 297 | 297 | ** only index the chat content if the chatfts1 table does not already |
| 298 | 298 | ** exist. |
| 299 | 299 | */ |
| 300 | 300 | void chat_rebuild_index(int bForce){ |
| 301 | + if( !db_table_exists("repository","chat") ) return; | |
| 301 | 302 | if( bForce!=0 ){ |
| 302 | 303 | db_multi_exec("DROP TABLE IF EXISTS chatfts1"); |
| 303 | 304 | } |
| 304 | 305 | if( bForce!=0 || !db_table_exists("repository", "chatfts1") ){ |
| 305 | 306 | const int tokType = search_tokenizer_type(0); |
| @@ -1245,10 +1246,19 @@ | ||
| 1245 | 1246 | ** |
| 1246 | 1247 | ** > fossil chat url |
| 1247 | 1248 | ** |
| 1248 | 1249 | ** Show the default URL used to access the chat server. |
| 1249 | 1250 | ** |
| 1251 | +** > fossil chat purge | |
| 1252 | +** | |
| 1253 | +** Remove chat messages that are older than chat-keep-days and | |
| 1254 | +** which are not one of the most recent chat-keep-count message. | |
| 1255 | +** | |
| 1256 | +** > fossil chat reindex | |
| 1257 | +** | |
| 1258 | +** Rebuild the full-text search index for chat | |
| 1259 | +** | |
| 1250 | 1260 | ** Additional subcommands may be added in the future. |
| 1251 | 1261 | */ |
| 1252 | 1262 | void chat_command(void){ |
| 1253 | 1263 | const char *zUrl = find_option("remote",0,1); |
| 1254 | 1264 | int urlFlags = 0; |
| @@ -1452,12 +1462,17 @@ | ||
| 1452 | 1462 | } |
| 1453 | 1463 | }else if( strcmp(g.argv[2],"url")==0 ){ |
| 1454 | 1464 | /* Show the URL to access chat. */ |
| 1455 | 1465 | fossil_print("%s/chat\n", zUrl); |
| 1456 | 1466 | }else if( strcmp(g.argv[2],"purge")==0 ){ |
| 1457 | - /* Undocumented debugging command that calls chat_purge() */ | |
| 1467 | + /* clear out expired chat messages: chat messages that are older then | |
| 1468 | + ** chat-keep-days and that are not one or the most recent chat-keep-count | |
| 1469 | + ** messages. */ | |
| 1458 | 1470 | chat_create_tables(); |
| 1459 | 1471 | chat_purge(); |
| 1472 | + }else if( strcmp(g.argv[2],"reindex")==0 ){ | |
| 1473 | + /* Rebuild the FTS5 index on chat content */ | |
| 1474 | + chat_rebuild_index(1); | |
| 1460 | 1475 | }else{ |
| 1461 | 1476 | fossil_fatal("no such subcommand \"%s\". Use --help for help", g.argv[2]); |
| 1462 | 1477 | } |
| 1463 | 1478 | } |
| 1464 | 1479 |
| --- src/chat.c | |
| +++ src/chat.c | |
| @@ -296,10 +296,11 @@ | |
| 296 | ** chatfts1 table and recreate/reindex it. If bForce is 0, it will |
| 297 | ** only index the chat content if the chatfts1 table does not already |
| 298 | ** exist. |
| 299 | */ |
| 300 | void chat_rebuild_index(int bForce){ |
| 301 | if( bForce!=0 ){ |
| 302 | db_multi_exec("DROP TABLE IF EXISTS chatfts1"); |
| 303 | } |
| 304 | if( bForce!=0 || !db_table_exists("repository", "chatfts1") ){ |
| 305 | const int tokType = search_tokenizer_type(0); |
| @@ -1245,10 +1246,19 @@ | |
| 1245 | ** |
| 1246 | ** > fossil chat url |
| 1247 | ** |
| 1248 | ** Show the default URL used to access the chat server. |
| 1249 | ** |
| 1250 | ** Additional subcommands may be added in the future. |
| 1251 | */ |
| 1252 | void chat_command(void){ |
| 1253 | const char *zUrl = find_option("remote",0,1); |
| 1254 | int urlFlags = 0; |
| @@ -1452,12 +1462,17 @@ | |
| 1452 | } |
| 1453 | }else if( strcmp(g.argv[2],"url")==0 ){ |
| 1454 | /* Show the URL to access chat. */ |
| 1455 | fossil_print("%s/chat\n", zUrl); |
| 1456 | }else if( strcmp(g.argv[2],"purge")==0 ){ |
| 1457 | /* Undocumented debugging command that calls chat_purge() */ |
| 1458 | chat_create_tables(); |
| 1459 | chat_purge(); |
| 1460 | }else{ |
| 1461 | fossil_fatal("no such subcommand \"%s\". Use --help for help", g.argv[2]); |
| 1462 | } |
| 1463 | } |
| 1464 |
| --- src/chat.c | |
| +++ src/chat.c | |
| @@ -296,10 +296,11 @@ | |
| 296 | ** chatfts1 table and recreate/reindex it. If bForce is 0, it will |
| 297 | ** only index the chat content if the chatfts1 table does not already |
| 298 | ** exist. |
| 299 | */ |
| 300 | void chat_rebuild_index(int bForce){ |
| 301 | if( !db_table_exists("repository","chat") ) return; |
| 302 | if( bForce!=0 ){ |
| 303 | db_multi_exec("DROP TABLE IF EXISTS chatfts1"); |
| 304 | } |
| 305 | if( bForce!=0 || !db_table_exists("repository", "chatfts1") ){ |
| 306 | const int tokType = search_tokenizer_type(0); |
| @@ -1245,10 +1246,19 @@ | |
| 1246 | ** |
| 1247 | ** > fossil chat url |
| 1248 | ** |
| 1249 | ** Show the default URL used to access the chat server. |
| 1250 | ** |
| 1251 | ** > fossil chat purge |
| 1252 | ** |
| 1253 | ** Remove chat messages that are older than chat-keep-days and |
| 1254 | ** which are not one of the most recent chat-keep-count message. |
| 1255 | ** |
| 1256 | ** > fossil chat reindex |
| 1257 | ** |
| 1258 | ** Rebuild the full-text search index for chat |
| 1259 | ** |
| 1260 | ** Additional subcommands may be added in the future. |
| 1261 | */ |
| 1262 | void chat_command(void){ |
| 1263 | const char *zUrl = find_option("remote",0,1); |
| 1264 | int urlFlags = 0; |
| @@ -1452,12 +1462,17 @@ | |
| 1462 | } |
| 1463 | }else if( strcmp(g.argv[2],"url")==0 ){ |
| 1464 | /* Show the URL to access chat. */ |
| 1465 | fossil_print("%s/chat\n", zUrl); |
| 1466 | }else if( strcmp(g.argv[2],"purge")==0 ){ |
| 1467 | /* clear out expired chat messages: chat messages that are older then |
| 1468 | ** chat-keep-days and that are not one or the most recent chat-keep-count |
| 1469 | ** messages. */ |
| 1470 | chat_create_tables(); |
| 1471 | chat_purge(); |
| 1472 | }else if( strcmp(g.argv[2],"reindex")==0 ){ |
| 1473 | /* Rebuild the FTS5 index on chat content */ |
| 1474 | chat_rebuild_index(1); |
| 1475 | }else{ |
| 1476 | fossil_fatal("no such subcommand \"%s\". Use --help for help", g.argv[2]); |
| 1477 | } |
| 1478 | } |
| 1479 |
+25
-10
| --- src/setup.c | ||
| +++ src/setup.c | ||
| @@ -1591,10 +1591,13 @@ | ||
| 1591 | 1591 | } |
| 1592 | 1592 | |
| 1593 | 1593 | style_set_current_feature("setup"); |
| 1594 | 1594 | style_header("Chat Configuration"); |
| 1595 | 1595 | db_begin_transaction(); |
| 1596 | + if( P("rbldchatidx") && cgi_csrf_safe(2) ){ | |
| 1597 | + chat_rebuild_index(1); | |
| 1598 | + } | |
| 1596 | 1599 | @ <form action="%R/setup_chat" method="post"><div> |
| 1597 | 1600 | login_insert_csrf_secret(); |
| 1598 | 1601 | @ <input type="submit" name="submit" value="Apply Changes"></p> |
| 1599 | 1602 | @ <hr> |
| 1600 | 1603 | entry_attribute("Initial Chat History Size", 10, |
| @@ -1643,12 +1646,15 @@ | ||
| 1643 | 1646 | "chat-alert-sound", "snd", azAlerts[0], |
| 1644 | 1647 | count(azAlerts)/2, azAlerts); |
| 1645 | 1648 | @ <p>The sound used in the client-side chat to indicate that a new |
| 1646 | 1649 | @ chat message has arrived. |
| 1647 | 1650 | @ (Property: "chat-alert-sound")</p> |
| 1651 | + | |
| 1648 | 1652 | @ <hr/> |
| 1649 | - @ <p><input type="submit" name="submit" value="Apply Changes"></p> | |
| 1653 | + @ <p><input type="submit" name="submit" value="Apply Changes"> | |
| 1654 | + @ <input type="submit" name="rbldchatidx"\ | |
| 1655 | + @ value="Rebuild Full-Text Search Index"></p> | |
| 1650 | 1656 | @ </div></form> |
| 1651 | 1657 | db_end_transaction(0); |
| 1652 | 1658 | @ <script nonce="%h(style_nonce())"> |
| 1653 | 1659 | @ (function(){ |
| 1654 | 1660 | @ var w = document.getElementById('idsnd'); |
| @@ -2342,19 +2348,24 @@ | ||
| 2342 | 2348 | @ <br> |
| 2343 | 2349 | onoff_attribute("Search Built-in Help Text", "search-help", "sh", 0, 0); |
| 2344 | 2350 | @ <hr> |
| 2345 | 2351 | @ <p><input type="submit" name="submit" value="Apply Changes"></p> |
| 2346 | 2352 | @ <hr> |
| 2347 | - if( P("fts0") ){ | |
| 2348 | - search_drop_index(); | |
| 2349 | - }else if( P("fts1") ){ | |
| 2350 | - const char *zTokenizer = PD("ftstok","off"); | |
| 2351 | - search_set_tokenizer(zTokenizer); | |
| 2352 | - search_drop_index(); | |
| 2353 | - search_create_index(); | |
| 2354 | - search_fill_index(); | |
| 2355 | - search_update_index(search_restrict(SRCH_ALL)); | |
| 2353 | + if( cgi_csrf_safe(2) ){ | |
| 2354 | + if( P("fts0") ){ | |
| 2355 | + search_drop_index(); | |
| 2356 | + }else if( P("fts1") ){ | |
| 2357 | + const char *zTokenizer = PD("ftstok","off"); | |
| 2358 | + search_set_tokenizer(zTokenizer); | |
| 2359 | + search_drop_index(); | |
| 2360 | + search_create_index(); | |
| 2361 | + search_fill_index(); | |
| 2362 | + search_update_index(search_restrict(SRCH_ALL)); | |
| 2363 | + } | |
| 2364 | + if( P("rbldchatidx") ){ | |
| 2365 | + chat_rebuild_index(1); | |
| 2366 | + } | |
| 2356 | 2367 | } |
| 2357 | 2368 | if( search_index_exists() ){ |
| 2358 | 2369 | int pgsz = db_int64(0, "PRAGMA repository.page_size;"); |
| 2359 | 2370 | i64 nTotal = db_int64(0, "PRAGMA repository.page_count;")*pgsz; |
| 2360 | 2371 | i64 nFts = db_int64(0, "SELECT count(*) FROM dbstat" |
| @@ -2367,10 +2378,14 @@ | ||
| 2367 | 2378 | @ but takes up space. The index is currently using about %s(zSize) |
| 2368 | 2379 | @ or %.1f(100.0*(double)nFts/(double)nTotal)%% of the repository.</p> |
| 2369 | 2380 | select_fts_tokenizer(); |
| 2370 | 2381 | @ <p><input type="submit" name="fts0" value="Delete The Full-Text Index"> |
| 2371 | 2382 | @ <input type="submit" name="fts1" value="Rebuild The Full-Text Index"> |
| 2383 | + if( db_table_exists("repository","chat") ){ | |
| 2384 | + @ <input type="submit" name="rbldchatidx" \ | |
| 2385 | + @ value="Rebuild The Chat FTS Index"> | |
| 2386 | + } | |
| 2372 | 2387 | style_submenu_element("FTS Index Debugging","%R/test-ftsdocs"); |
| 2373 | 2388 | }else{ |
| 2374 | 2389 | @ <p>The SQLite search index is disabled. All searching will be |
| 2375 | 2390 | @ a full-text scan. This usually works fine, but can be slow for |
| 2376 | 2391 | @ larger repositories.</p> |
| 2377 | 2392 |
| --- src/setup.c | |
| +++ src/setup.c | |
| @@ -1591,10 +1591,13 @@ | |
| 1591 | } |
| 1592 | |
| 1593 | style_set_current_feature("setup"); |
| 1594 | style_header("Chat Configuration"); |
| 1595 | db_begin_transaction(); |
| 1596 | @ <form action="%R/setup_chat" method="post"><div> |
| 1597 | login_insert_csrf_secret(); |
| 1598 | @ <input type="submit" name="submit" value="Apply Changes"></p> |
| 1599 | @ <hr> |
| 1600 | entry_attribute("Initial Chat History Size", 10, |
| @@ -1643,12 +1646,15 @@ | |
| 1643 | "chat-alert-sound", "snd", azAlerts[0], |
| 1644 | count(azAlerts)/2, azAlerts); |
| 1645 | @ <p>The sound used in the client-side chat to indicate that a new |
| 1646 | @ chat message has arrived. |
| 1647 | @ (Property: "chat-alert-sound")</p> |
| 1648 | @ <hr/> |
| 1649 | @ <p><input type="submit" name="submit" value="Apply Changes"></p> |
| 1650 | @ </div></form> |
| 1651 | db_end_transaction(0); |
| 1652 | @ <script nonce="%h(style_nonce())"> |
| 1653 | @ (function(){ |
| 1654 | @ var w = document.getElementById('idsnd'); |
| @@ -2342,19 +2348,24 @@ | |
| 2342 | @ <br> |
| 2343 | onoff_attribute("Search Built-in Help Text", "search-help", "sh", 0, 0); |
| 2344 | @ <hr> |
| 2345 | @ <p><input type="submit" name="submit" value="Apply Changes"></p> |
| 2346 | @ <hr> |
| 2347 | if( P("fts0") ){ |
| 2348 | search_drop_index(); |
| 2349 | }else if( P("fts1") ){ |
| 2350 | const char *zTokenizer = PD("ftstok","off"); |
| 2351 | search_set_tokenizer(zTokenizer); |
| 2352 | search_drop_index(); |
| 2353 | search_create_index(); |
| 2354 | search_fill_index(); |
| 2355 | search_update_index(search_restrict(SRCH_ALL)); |
| 2356 | } |
| 2357 | if( search_index_exists() ){ |
| 2358 | int pgsz = db_int64(0, "PRAGMA repository.page_size;"); |
| 2359 | i64 nTotal = db_int64(0, "PRAGMA repository.page_count;")*pgsz; |
| 2360 | i64 nFts = db_int64(0, "SELECT count(*) FROM dbstat" |
| @@ -2367,10 +2378,14 @@ | |
| 2367 | @ but takes up space. The index is currently using about %s(zSize) |
| 2368 | @ or %.1f(100.0*(double)nFts/(double)nTotal)%% of the repository.</p> |
| 2369 | select_fts_tokenizer(); |
| 2370 | @ <p><input type="submit" name="fts0" value="Delete The Full-Text Index"> |
| 2371 | @ <input type="submit" name="fts1" value="Rebuild The Full-Text Index"> |
| 2372 | style_submenu_element("FTS Index Debugging","%R/test-ftsdocs"); |
| 2373 | }else{ |
| 2374 | @ <p>The SQLite search index is disabled. All searching will be |
| 2375 | @ a full-text scan. This usually works fine, but can be slow for |
| 2376 | @ larger repositories.</p> |
| 2377 |
| --- src/setup.c | |
| +++ src/setup.c | |
| @@ -1591,10 +1591,13 @@ | |
| 1591 | } |
| 1592 | |
| 1593 | style_set_current_feature("setup"); |
| 1594 | style_header("Chat Configuration"); |
| 1595 | db_begin_transaction(); |
| 1596 | if( P("rbldchatidx") && cgi_csrf_safe(2) ){ |
| 1597 | chat_rebuild_index(1); |
| 1598 | } |
| 1599 | @ <form action="%R/setup_chat" method="post"><div> |
| 1600 | login_insert_csrf_secret(); |
| 1601 | @ <input type="submit" name="submit" value="Apply Changes"></p> |
| 1602 | @ <hr> |
| 1603 | entry_attribute("Initial Chat History Size", 10, |
| @@ -1643,12 +1646,15 @@ | |
| 1646 | "chat-alert-sound", "snd", azAlerts[0], |
| 1647 | count(azAlerts)/2, azAlerts); |
| 1648 | @ <p>The sound used in the client-side chat to indicate that a new |
| 1649 | @ chat message has arrived. |
| 1650 | @ (Property: "chat-alert-sound")</p> |
| 1651 | |
| 1652 | @ <hr/> |
| 1653 | @ <p><input type="submit" name="submit" value="Apply Changes"> |
| 1654 | @ <input type="submit" name="rbldchatidx"\ |
| 1655 | @ value="Rebuild Full-Text Search Index"></p> |
| 1656 | @ </div></form> |
| 1657 | db_end_transaction(0); |
| 1658 | @ <script nonce="%h(style_nonce())"> |
| 1659 | @ (function(){ |
| 1660 | @ var w = document.getElementById('idsnd'); |
| @@ -2342,19 +2348,24 @@ | |
| 2348 | @ <br> |
| 2349 | onoff_attribute("Search Built-in Help Text", "search-help", "sh", 0, 0); |
| 2350 | @ <hr> |
| 2351 | @ <p><input type="submit" name="submit" value="Apply Changes"></p> |
| 2352 | @ <hr> |
| 2353 | if( cgi_csrf_safe(2) ){ |
| 2354 | if( P("fts0") ){ |
| 2355 | search_drop_index(); |
| 2356 | }else if( P("fts1") ){ |
| 2357 | const char *zTokenizer = PD("ftstok","off"); |
| 2358 | search_set_tokenizer(zTokenizer); |
| 2359 | search_drop_index(); |
| 2360 | search_create_index(); |
| 2361 | search_fill_index(); |
| 2362 | search_update_index(search_restrict(SRCH_ALL)); |
| 2363 | } |
| 2364 | if( P("rbldchatidx") ){ |
| 2365 | chat_rebuild_index(1); |
| 2366 | } |
| 2367 | } |
| 2368 | if( search_index_exists() ){ |
| 2369 | int pgsz = db_int64(0, "PRAGMA repository.page_size;"); |
| 2370 | i64 nTotal = db_int64(0, "PRAGMA repository.page_count;")*pgsz; |
| 2371 | i64 nFts = db_int64(0, "SELECT count(*) FROM dbstat" |
| @@ -2367,10 +2378,14 @@ | |
| 2378 | @ but takes up space. The index is currently using about %s(zSize) |
| 2379 | @ or %.1f(100.0*(double)nFts/(double)nTotal)%% of the repository.</p> |
| 2380 | select_fts_tokenizer(); |
| 2381 | @ <p><input type="submit" name="fts0" value="Delete The Full-Text Index"> |
| 2382 | @ <input type="submit" name="fts1" value="Rebuild The Full-Text Index"> |
| 2383 | if( db_table_exists("repository","chat") ){ |
| 2384 | @ <input type="submit" name="rbldchatidx" \ |
| 2385 | @ value="Rebuild The Chat FTS Index"> |
| 2386 | } |
| 2387 | style_submenu_element("FTS Index Debugging","%R/test-ftsdocs"); |
| 2388 | }else{ |
| 2389 | @ <p>The SQLite search index is disabled. All searching will be |
| 2390 | @ a full-text scan. This usually works fine, but can be slow for |
| 2391 | @ larger repositories.</p> |
| 2392 |