Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove firestore and memory cache #26

Merged
merged 2 commits into from
Dec 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions cmd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,11 @@ var genCmd = &cobra.Command{
panic("invalid storage type: " + config.Storage)
}

memoryStorage := storage.NewMemoryWithOtherStorage(store)
iroha := lib.NewIroha(words, memoryStorage, config.DepthOptions)
iroha := lib.NewIroha(words, store, config.DepthOptions)

if config.ResetProgress {
log.Println("progress is reset")
if err := memoryStorage.ResetProgress(ctx); err != nil {
if err := store.ResetProgress(ctx); err != nil {
panic(err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/iroha.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (i *Iroha) searchByBits(usedIndices []int, katakanaBitsAndWords []*ktkn.Kat
goroutineMode := depth >= i.depths.MinParallel && depth <= i.depths.MaxParallel
if goroutineMode {
eg := errgroup.Group{}
wordListChan := make(chan []*ktkn.Word, 100)
wordListChan := make(chan []*ktkn.Word, 1000000)
for index, word := range katakanaAndWordBits.Words {
gWord := word
newIndices := generateNewUsedIndices(usedIndices, index)
Expand Down
25 changes: 1 addition & 24 deletions storage/firestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"reflect"
"time"

cstorage "cloud.google.com/go/storage"

Expand Down Expand Up @@ -100,7 +99,7 @@ func (f *FireStore) removeProgressByState(ctx context.Context, progress int) err
}

func (f *FireStore) Start(ctx context.Context, indices []int) error {
return f.updateProgress(ctx, indices, progressProcessing)
return nil
}

func (f *FireStore) ResetProgress(ctx context.Context) error {
Expand All @@ -125,31 +124,9 @@ func (f *FireStore) Set(ctx context.Context, indices []int, wordsList [][]*ktkn.
if err := f.cstorageClient.SaveWordsList(ctx, indices, wordsList); err != nil {
return errors.Wrap(err, "failed to set wordsList to cloud storage")
}
if err := f.updateProgress(ctx, indices, progressDone); err != nil {
return errors.Wrap(err, "failed to update progress to done")
}

return nil
}

func (f *FireStore) Get(ctx context.Context, indices []int) ([][]*ktkn.Word, bool, error) {
L:
for {
// FIXME: watch document
progress, err := f.getProgress(ctx, indices)
if err != nil {
return nil, false, err
}

switch progress {
case progressNotStarted:
return nil, false, nil
case progressDone:
break L
case progressProcessing:
time.Sleep(500 * time.Millisecond)
}
}

return f.cstorageClient.Get(ctx, indices)
}