Skip to content

Commit

Permalink
feat: improve push impl of firebase service
Browse files Browse the repository at this point in the history
  • Loading branch information
theiskaa committed Dec 12, 2022
1 parent 032ed65 commit 7065a4a
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions lib/services/firebase_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ func (s *FirebaseService) Rename(editNode models.EditNode) error {
}

// ClearNodes removes all nodes from collection.
// TODO: improve the speed of clearing
func (s *FirebaseService) ClearNodes() ([]models.Node, []error) {
nodes, _, err := s.GetAll("", "", models.NotyaIgnoreFiles)
if err != nil && err.Error() != assets.EmptyWorkingDirectory.Error() {
Expand Down Expand Up @@ -679,38 +680,36 @@ func (s *FirebaseService) Push(remote ServiceRepo) ([]models.Node, []error) {
pushed := []models.Node{}

for _, node := range nodes {
exists, err := remote.IsNodeExists(node)
if err != nil {
errors = append(errors, err)
continue
}
exists, _ := remote.IsNodeExists(node)

if !exists {
if _, err := remote.Create(node.ToNote()); err != nil {
errors = append(errors, err)
if node.IsFolder() && !exists {
if _, err := remote.Mkdir(node.ToFolder()); err != nil {
errors = append(errors, assets.CannotDoSth("push", node.Title, err))
} else {
pushed = append(pushed, node)
}

continue
}

r, err := remote.View(node.ToNote())
if err != nil {
errors = append(errors, err)
continue
}
r, _ := remote.View(node.ToNote())
if !exists {
if _, err := remote.Create(node.ToNote()); err != nil {
errors = append(errors, assets.CannotDoSth("push", node.Title, err))
} else {
pushed = append(pushed, node)
}

if r.Body == node.Body {
continue
}

if _, err := remote.Edit(node.ToNote()); err != nil {
errors = append(errors, err)
} else {
pushed = append(pushed, node)
if r.Body != node.Body {
if _, err := remote.Edit(node.ToNote()); err != nil {
errors = append(errors, assets.CannotDoSth("push", node.Title, err))
} else {
pushed = append(pushed, node)
}
}

}

return pushed, errors
Expand Down

0 comments on commit 7065a4a

Please sign in to comment.