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

Config file written very frequently #120

Closed
afh opened this issue Apr 21, 2021 · 2 comments
Closed

Config file written very frequently #120

afh opened this issue Apr 21, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@afh
Copy link
Contributor

afh commented Apr 21, 2021

While working on some PRs and having the cointop configuration file open in my $EDITOR I noticed that cointop made changes to the config file. Inspecting filesystem operations on config.toml using fswatch it appears the configuration file is written to around 10 times per minutes (give or take a few) when cointop is running (see code snippet below), which seems unnecessary.

Any idea where that might originate from, @miguelmota?
I'd appreciate some pointers as to where the cause may lie and am happy to look into it and provide a PR.

% fswatch -tu ~/src/dotfiles/cointop/config.toml
Wed Apr 21 07:00:12 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:00:16 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:00:22 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:00:27 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:00:32 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:00:36 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:00:42 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:00:47 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:00:51 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:00:56 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:01:02 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:01:06 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:01:12 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:01:17 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:01:21 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:01:26 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:01:32 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:01:36 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:01:42 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:01:47 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:01:51 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:01:56 2021 /Users/afh/src/dotfiles/cointop/config.toml
Wed Apr 21 07:02:02 2021 /Users/afh/src/dotfiles/cointop/config.toml
@afh afh changed the title Config file written every very frequently Config file written very frequently Apr 24, 2021
miguelmota added a commit that referenced this issue Apr 24, 2021
@miguelmota
Copy link
Member

@afh Looks like there were a few places that it was making unnecessary save write calls.

Writing to the config file here uses outil.WriteFile which triggers 4 fswatch events .

package main

import (
	"io/ioutil"
	"os"
)

func main() {
	path := "./file.txt"
	data := []byte("hello")
	if err := ioutil.WriteFile(path, data, os.FileMode(0644)); err != nil {
		panic(err)
	}
}
$ fswatch -tu file.txt
Sat 24 Apr 2021 09:49:26 PM GMT /home/mota/go/src/github.com/miguelmota/test/file.txt
Sat 24 Apr 2021 09:49:26 PM GMT /home/mota/go/src/github.com/miguelmota/test/file.txt
Sat 24 Apr 2021 09:49:27 PM GMT /home/mota/go/src/github.com/miguelmota/test/file.txt
Sat 24 Apr 2021 09:49:27 PM GMT /home/mota/go/src/github.com/miguelmota/test/file.txt

The method ct.Save() is invoked when performing actions like toggling favorites, editing portfolio, price alerts, preferred currency, etc. which causes file writes.

@miguelmota miguelmota added the bug Something isn't working label Apr 25, 2021
@afh
Copy link
Contributor Author

afh commented Apr 26, 2021

Nice changes to reduce number of save calls, well done! 👏

I wonder if the the very frequent file writes I saw possibly had to do with two running instances of cointop…
I'm going to close this issue for now and will re-open with more reproducible instructions should the issue occur again.

@afh afh closed this as completed Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants