~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/search.py

  • Committer: Michael Hudson
  • Date: 2010-05-07 01:03:17 UTC
  • mfrom: (414.1.1 loggerhead)
  • Revision ID: michael.hudson@canonical.com-20100507010317-kr5ipx6qgn65636o
(mkanat) use a global lock to protect access to the lru cache

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# along with this program; if not, write to the Free Software
18
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
19
#
20
 
import sets
21
 
try:
22
 
    from bzrlib.plugins.search import errors
23
 
    from bzrlib.plugins.search import index as _mod_index
24
 
    from bzrlib.plugins.search.index import FileTextHit, RevisionHit
25
 
except ImportError:
26
 
    _mod_index = None
 
20
 
 
21
_mod_index = None
 
22
def import_search():
 
23
    global errors, _mod_index, FileTextHit, RevisionHit
 
24
    if _mod_index is not None:
 
25
        return
 
26
    try:
 
27
        from bzrlib.plugins.search import errors
 
28
        from bzrlib.plugins.search import index as _mod_index
 
29
        from bzrlib.plugins.search.index import FileTextHit, RevisionHit
 
30
    except ImportError:
 
31
        _mod_index = None
27
32
 
28
33
 
29
34
def search_revisions(branch, query_list, suggest=False):
36
41
    param suggest: Optional flag to request suggestions instead of results
37
42
    return: A list for results, either revision ids or terms
38
43
    """
 
44
    import_search()
39
45
    if _mod_index is None:
40
46
        return None # None indicates could-not-search
41
47
    try:
59
65
                    revid_list.append(result.text_key[1])
60
66
                elif isinstance(result, RevisionHit):
61
67
                    revid_list.append(result.revision_key[0])
62
 
            return list(sets.Set(revid_list))
 
68
            return list(set(revid_list))
63
69
    finally:
64
70
        index._branch.unlock()