#include "../../context.h"
#include "../../ctdl_module.h"
-
// These can be global variables because only one indexer runs at a time.
Array *messages_to_be_indexed = NULL;
long highest_msg_already_indexed = 0;
// Here it is ... do each message!
long msgnum = 0;
long prev_msgnum = 0;
+ time_t started_indexing_at = time(NULL);
for (i=0; i<array_len(messages_to_be_indexed); ++i) {
memcpy(&msgnum, array_get_element_at(messages_to_be_indexed, i), sizeof(long));
}
prev_msgnum = msgnum;
+ if (time(NULL) - started_indexing_at >= MAXIMUM_INDEXER_RUN_TIME) {
+ syslog(LOG_DEBUG, "fulltext: indexer has run for %ld seconds; yielding the thread", time(NULL) - started_indexing_at);
+ i = array_len(messages_to_be_indexed); // go out of scope to make it stop
+ }
}
array_free(messages_to_be_indexed);
if (!threading) {
CtdlRegisterProtoHook(cmd_srch, "SRCH", "Full text search");
CtdlRegisterDeleteHook(ft_delete_remove);
- CtdlRegisterSessionHook(do_fulltext_indexing, EVT_TIMER, PRIO_CLEANUP + 300);
+ CtdlRegisterSessionHook(do_fulltext_indexing, EVT_HOUSE, PRIO_CLEANUP + 300);
}
// return our module name for the log
return "fulltext";
void ft_index_message(long msgnum, int op);
Array *CtdlFullTextSearch(const char *search_string);
+
+// After this many seconds, the indexer will stop and yield the housekeeping thread.
+// On the next cycle it will run again and pick up where it left off.
+#define MAXIMUM_INDEXER_RUN_TIME 60