Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b0530560
Commit
b0530560
authored
Jan 29, 2016
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ES: respo indexer increments index
parent
03370b01
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
19 deletions
+32
-19
app/models/index_status.rb
app/models/index_status.rb
+2
-0
lib/tasks/gitlab/elastic.rake
lib/tasks/gitlab/elastic.rake
+30
-19
No files found.
app/models/index_status.rb
View file @
b0530560
class
IndexStatus
<
ActiveRecord
::
Base
belongs_to
:project
validates
:project_id
,
uniqueness:
true
end
lib/tasks/gitlab/elastic.rake
View file @
b0530560
...
...
@@ -4,30 +4,27 @@ namespace :gitlab do
task
index_repositories: :environment
do
Repository
.
__elasticsearch__
.
create_index!
projects
=
Project
if
ENV
[
'ID_FROM'
]
projects
=
projects
.
where
(
"id >= ?"
,
ENV
[
'ID_FROM'
])
end
if
ENV
[
'ID_TO'
]
projects
=
projects
.
where
(
"id <= ?"
,
ENV
[
'ID_TO'
])
end
projects
=
apply_project_filters
(
Project
)
projects
.
find_each
do
|
project
|
if
project
.
repository
.
exists?
&&
!
project
.
repository
.
empty?
puts
"Indexing
#{
project
.
name_with_namespace
}
..."
puts
"Indexing
#{
project
.
name_with_namespace
}
(ID=
#{
project
.
id
}
)
..."
begin
# During indexing the new commits can be pushed,
# this parameter only indicates that at least this commit is in index
heeads_sha
=
project
.
repository
.
commit
.
sha
IndexStatus
.
find_or_create_by
(
last_commit:
heeads_sha
,
project:
project
)
index_status
=
IndexStatus
.
find_or_create_by
(
project:
project
)
heads_sha
=
project
.
repository
.
commit
.
sha
project
.
repository
.
index_commits
project
.
repository
.
index_blobs
if
index_status
.
last_commit
==
heads_sha
puts
"Skipped"
.
yellow
next
end
begin
project
.
repository
.
index_commits
(
from_rev:
project
.
index_status
.
last_commit
)
project
.
repository
.
index_blobs
(
from_rev:
project
.
index_status
.
last_commit
)
project
.
index_status
.
update
(
indexed_at:
DateTime
.
now
)
# During indexing the new commits can be pushed,
# the last_commit parameter only indicates that at least this commit is in index
index_status
.
update
(
last_commit:
heads_sha
,
indexed_at:
DateTime
.
now
)
puts
"Done!"
.
green
rescue
StandardError
=>
e
puts
"
#{
e
.
message
}
, trace -
#{
e
.
backtrace
}
"
...
...
@@ -40,7 +37,9 @@ namespace :gitlab do
task
index_wikis: :environment
do
ProjectWiki
.
__elasticsearch__
.
create_index!
Project
.
where
(
wiki_enabled:
true
).
find_each
do
|
project
|
projects
=
apply_project_filters
(
Project
.
where
(
wiki_enabled:
true
))
projects
.
find_each
do
|
project
|
unless
project
.
wiki
.
empty?
puts
"Indexing wiki of
#{
project
.
name_with_namespace
}
..."
begin
...
...
@@ -81,5 +80,17 @@ namespace :gitlab do
klass
.
__elasticsearch__
.
create_index!
end
end
def
apply_project_filters
(
projects
)
if
ENV
[
'ID_FROM'
]
projects
=
projects
.
where
(
"id >= ?"
,
ENV
[
'ID_FROM'
])
end
if
ENV
[
'ID_TO'
]
projects
=
projects
.
where
(
"id <= ?"
,
ENV
[
'ID_TO'
])
end
projects
end
end
end
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment