diff --git a/releases/releases.json b/releases/releases.json index ad22998..c58c9bf 100644 --- a/releases/releases.json +++ b/releases/releases.json @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9611e48f2e9bfcdd217d81a429b399ec05cf3db4a581d19d49a9f70a9a90385f +oid sha256:863fcb78eb72033f6a58ede1c92156c0e04e00694cc8febac6a060710a18e222 size 965663 diff --git a/solc.go b/solc.go index 03cf17d..10cf9da 100644 --- a/solc.go +++ b/solc.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" "runtime" + "time" ) // Solc represents the main structure for interacting with the Solidity compiler. @@ -15,10 +16,10 @@ type Solc struct { client *http.Client gOOSFunc func() string localReleases []Version + lastSync time.Time } // New initializes and returns a new instance of the Solc structure. -// It requires a context and a configuration to be provided. func New(ctx context.Context, config *Config) (*Solc, error) { if config == nil { return nil, fmt.Errorf("config needs to be provided") @@ -43,6 +44,11 @@ func (s *Solc) GetContext() context.Context { return s.ctx } +// LastSyncTime retrieves the last time the Solc instance was synced. +func (s *Solc) LastSyncTime() time.Time { + return s.lastSync +} + // GetConfig retrieves the configuration associated with the Solc instance. func (s *Solc) GetConfig() *Config { return s.config diff --git a/syncer.go b/syncer.go index 23310c0..41452ba 100644 --- a/syncer.go +++ b/syncer.go @@ -21,6 +21,12 @@ func (s *Solc) SyncReleases() ([]Version, error) { var allVersions []Version page := 1 + // Sync maximum 4 times per day in order to increase the speed of the sync process when there's really + // no need to sync more often than that. + if time.Since(s.lastSync) < time.Duration(6*time.Hour) { + return s.localReleases, nil + } + for { url := fmt.Sprintf("%s?page=%d", s.config.GetReleasesUrl(), page) req, err := http.NewRequest("GET", url, nil) @@ -72,6 +78,7 @@ func (s *Solc) SyncReleases() ([]Version, error) { } s.localReleases = allVersions + s.lastSync = time.Now() return allVersions, nil } diff --git a/syncer_test.go b/syncer_test.go index ef00607..33466c8 100644 --- a/syncer_test.go +++ b/syncer_test.go @@ -54,6 +54,7 @@ func TestSyncer(t *testing.T) { assert.NoError(t, err) } + assert.NotNil(t, s.LastSyncTime()) }) } } @@ -108,6 +109,7 @@ func TestSyncOnce(t *testing.T) { assert.NoError(t, err) } + assert.NotNil(t, s.LastSyncTime()) }) } }