Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
liber
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
liber
Commits
ce2898f6
Commit
ce2898f6
authored
7 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Use batching to make reindexing faster
parent
1555c0d9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
database.go
+31
-6
31 additions, 6 deletions
database.go
with
31 additions
and
6 deletions
database.go
+
31
−
6
View file @
ce2898f6
...
...
@@ -225,7 +225,7 @@ func (db *Database) setupLevelDb(path string) error {
// Use 128MB of cache and a small Bloom filter.
opts
:=
&
ldbopt
.
Options
{
Filter
:
ldbfilter
.
NewBloomFilter
(
10
),
BlockCacheCapacity
:
2
<<
2
7
,
BlockCacheCapacity
:
1
<<
2
8
,
// 256MB
}
ldb
,
err
:=
leveldb
.
OpenFile
(
path
,
opts
)
...
...
@@ -495,10 +495,14 @@ func (db *Database) Restore(r io.Reader) error {
if
err
!=
nil
{
return
err
}
db
.
RawPut
(
key
,
value
)
count
++
if
count
%
1000
==
0
{
log
.
Printf
(
"restored %d entries"
,
count
)
}
}
log
.
Printf
(
"restore
d %d entries to the database
"
,
count
)
log
.
Printf
(
"restore
complete (%d entries)
"
,
count
)
return
db
.
Reindex
()
}
...
...
@@ -517,11 +521,32 @@ func (db *Database) Reindex() error {
return
err
}
// Scan the database and re-index everything.
return
db
.
onAllBooks
(
func
(
book
*
Book
)
error
{
db
.
index
.
Index
(
book
.
Id
.
String
(),
flatten
(
book
))
// Scan the database and re-index everything. Use batch
// indexing to achieve decent performance.
i
:=
0
start
:=
time
.
Now
()
batch
:=
db
.
index
.
NewBatch
()
if
err
:=
db
.
onAllBooks
(
func
(
book
*
Book
)
error
{
batch
.
Index
(
book
.
Id
.
String
(),
flatten
(
book
))
i
++
if
i
%
100
==
0
{
if
err
:=
db
.
index
.
Batch
(
batch
);
err
!=
nil
{
return
err
}
batch
=
db
.
index
.
NewBatch
()
}
return
nil
})
});
err
!=
nil
{
return
err
}
// Flush the batch indexer if not empty.
if
err
:=
db
.
index
.
Batch
(
batch
);
err
!=
nil
{
return
err
}
log
.
Printf
(
"re-indexing complete, %d documents in %g seconds"
,
i
,
time
.
Since
(
start
)
.
Seconds
())
return
nil
}
// Call a function for all books in the database.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment