# HG changeset patch # User Tero Marttila # Date 1234314275 -7200 # Node ID d30c88e89a7edbf4b52ca2fe0a2972b3141220dd # Parent ebdbda3dd5d00f6239ba6b29ef4e707e376608d7 move the LogSearchIndex open from handlers to log_search, and make it lazy diff -r ebdbda3dd5d0 -r d30c88e89a7e handlers.py --- a/handlers.py Wed Feb 11 02:21:43 2009 +0200 +++ b/handlers.py Wed Feb 11 03:04:35 2009 +0200 @@ -9,7 +9,7 @@ import urls, channels, helpers import preferences as prefs from preferences import preferences -import config +import config, log_search # load templates from here templates = template.TemplateLoader("templates", @@ -19,11 +19,6 @@ config = config, ) -# our LogSearch thing -# XXX: move elsewhere -import log_search -search_index = log_search.LogSearchIndex(config.LOG_CHANNELS, config.SEARCH_INDEX_PATH, 'r') - def index (request) : """ The topmost index page, display a list of available channels, perhaps some general stats @@ -214,7 +209,7 @@ if q : try : # do search - lines = search_index.search_simple(channel, q, count, skip) + lines = log_search.get_index().search_simple(channel, q, count, skip) # update max? if max and page > max : diff -r ebdbda3dd5d0 -r d30c88e89a7e log_search.py --- a/log_search.py Wed Feb 11 02:21:43 2009 +0200 +++ b/log_search.py Wed Feb 11 03:04:35 2009 +0200 @@ -7,7 +7,7 @@ import HyperEstraier as hype -import log_line, utils +import log_line, utils, config class LogSearchError (Exception) : """ @@ -304,3 +304,21 @@ max = count, skip = skip ) + +# global read-only index +_index = None + +def get_index () : + """ + Returns the default read-only index, suitable for searching + """ + + global _index + + # open? + if not _index : + _index = LogSearchIndex(config.LOG_CHANNELS, config.SEARCH_INDEX_PATH, 'r') + + # return + return _index +