Changeset 265

Show
Ignore:
Timestamp:
04/25/08 07:28:51 (7 months ago)
Author:
eric.dumin..@gmail.com
Message:

DocumentsController? checks if index has been created before any action.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/picolena/templates/app/controllers/documents_controller.rb

    r263 r265  
    88 
    99class DocumentsController < ApplicationController 
     10  before_filter :ensure_index_is_created, :except=> :index 
    1011  before_filter :check_if_valid_link, :only=> [:download, :content, :cached] 
    1112 
     
    5960    @document=Document.find_by_unique_id(@probably_unique_id) rescue no_valid_link 
    6061  end 
     62   
     63  def ensure_index_is_created 
     64    Indexer.ensure_index_existence 
     65    while Indexer.do_not_disturb_while_indexing do 
     66      sleep 1 
     67    end 
     68  end 
    6169 
    6270  # Flashes a warning and redirects to documents_url. 
  • trunk/lib/picolena/templates/app/models/indexer.rb

    r263 r265  
    44  # Number of threads that will be used during indexing process 
    55  @@max_threads_number = 8 
     6   
     7  cattr_reader :do_not_disturb_while_indexing 
    68 
    79  class << self 
    810    def index_every_directory(remove_first=false) 
     11      @@do_not_disturb_while_indexing=true 
    912      clear! if remove_first 
    1013      # Forces Finder.searcher and Finder.index to be reloaded, by removing them from the cache. 
     
    1720      log :debug => "Now optimizing index" 
    1821      index.optimize 
     22      @@do_not_disturb_while_indexing=false 
    1923      log :debug => "Indexing done in #{Time.now-start} s." 
    2024    end 
     
    2832 
    2933      indexing_list_chunks=indexing_list.in_transposed_slices(@@max_threads_number) 
    30  
    31       # It initializes the Index before launching multithreaded 
    32       # indexing. Otherwise, two threads could try to instantiate 
    33       # an IndexWriter at the same time, and get a 
    34       #  Ferret::Store::Lock::LockError 
    35       index 
    36  
     34       
     35      prepare_multi_threads_environment 
     36       
    3737      indexing_list_chunks.each_with_thread{|chunk| 
    3838        chunk.each{|filename| 
     
    124124      end 
    125125    end 
     126     
     127    def prepare_multi_threads_environment 
     128      # It initializes the Index before launching multithreaded 
     129      # indexing. Otherwise, two threads could try to instantiate 
     130      # an IndexWriter at the same time, and get a 
     131      #  Ferret::Store::Lock::LockError 
     132      index 
     133      # NOTE: is it really necessary? 
     134      # ActiveSupport sometime raises 
     135      #  Expected Object is NOT missing constant 
     136      # without. 
     137      Document 
     138      Finder 
     139      Query 
     140      PlainTextExtractor 
     141    end 
    126142  end 
    127143end