Commit 7b24d8ee authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'elastic_wiki_fix' into 'master'

Elastic search improvements

* Remove warning when you run index_repositories task first time and there is no index yet.

* Update wiki index dynamically. It has been forgotten.


See merge request !126
parents d9ac4023 7593a2e3
......@@ -22,7 +22,7 @@ module RepositoriesSearch
end
def self.import
Repository.__elasticsearch__.create_index! force: true
Repository.__elasticsearch__.create_index!
Project.find_each do |project|
if project.repository.exists? && !project.repository.empty?
......
......@@ -22,7 +22,7 @@ module WikiRepositoriesSearch
end
def self.import
ProjectWiki.__elasticsearch__.create_index! force: true
ProjectWiki.__elasticsearch__.create_index!
Project.where(wiki_enabled: true).find_each do |project|
unless project.wiki.empty?
......
......@@ -59,6 +59,7 @@ class Note < ActiveRecord::Base
# Scopes
scope :awards, ->{ where(is_award: true) }
scope :nonawards, ->{ where(is_award: false) }
scope :searchable, ->{ where("is_award IS FALSE AND system IS FALSE") }
scope :for_commit_id, ->(commit_id) { where(noteable_type: "Commit", commit_id: commit_id) }
scope :inline, ->{ where("line_code IS NOT NULL") }
scope :not_inline, ->{ where(line_code: [nil, '']) }
......
......@@ -94,6 +94,8 @@ class ProjectWiki
wiki.write_page(title, format, content, commit)
update_elastic_index
update_project_activity
rescue Gollum::DuplicatePageError => e
@error_message = "Duplicate page: #{e.message}"
......@@ -105,12 +107,16 @@ class ProjectWiki
wiki.update_page(page, page.name, format, content, commit)
update_elastic_index
update_project_activity
end
def delete_page(page, message = nil)
wiki.delete_page(page, commit_details(:deleted, message, page.title))
update_elastic_index
update_project_activity
end
......@@ -163,4 +169,8 @@ class ProjectWiki
def update_project_activity
@project.touch(:last_activity_at)
end
def update_elastic_index
index_blobs if Gitlab.config.elasticsearch.enabled
end
end
......@@ -251,6 +251,8 @@ Settings.gitlab['import_sources'] ||= ['github','bitbucket','gitlab','gitorious'
#
Settings['elasticsearch'] ||= Settingslogic.new({})
Settings.elasticsearch['enabled'] = false if Settings.elasticsearch['enabled'].nil?
Settings.elasticsearch['host'] = "localhost" if Settings.elasticsearch['host'].nil?
Settings.elasticsearch['port'] = 9200 if Settings.elasticsearch['port'].nil?
#
# CI
......
......@@ -14,7 +14,12 @@ namespace :gitlab do
task index_database: :environment do
[Project, Issue, MergeRequest, Snippet, Note, Milestone].each do |klass|
klass.__elasticsearch__.create_index!
klass.import
if klass == Note
Note.searchable.import
else
klass.import
end
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment