Skip to content

Commit

Permalink
Addressing feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
laurb9 committed Aug 25, 2020
1 parent 6121e25 commit ee1c30e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions config/stored_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type StoredRequests struct {
// Lazy-load the data.
// false (default): preload all the files in cache
// true: load data only when incoming requests ask for the stored resource
LazyLoad bool `mapstructure:"lazy_load"`
FilesLazyLoad bool `mapstructure:"filesystem_lazy_load"`
// Postgres configures Fetchers and EventProducers which read from a Postgres DB.
// Fetchers are in stored_requests/backends/db_fetcher/postgres.go
// EventProducers are in stored_requests/events/postgres
Expand Down Expand Up @@ -142,7 +142,7 @@ func (cfg *StoredRequests) validate(errs configErrors) configErrors {
if cfg.Postgres.CacheInitialization.Query != "" {
errs = append(errs, errors.New("stored_requests.postgres.initialize_caches.query must be empty if stored_requests.in_memory_cache=none"))
}
if cfg.Files && !cfg.LazyLoad {
if cfg.Files && !cfg.FilesLazyLoad {
// auto configure an in-memory static cache to replicate previous behavior (load and store all)
cfg.InMemoryCache.Type = "unbounded"
}
Expand Down
6 changes: 3 additions & 3 deletions stored_requests/backends/file_fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (
)

// NewFileFetcher lazy-loads various kinds of objects from the given directory
// Expected directory structure:
// Expected directory structure depends on data type - stored requests or categories,
// and may include:
// - stored_requests/{id}.json for stored requests
// - stored_imps/{id}.json for stored imps
// - {adserver}.json non-publisher specific primary adserver categories
// - {adserver}/{adserver}_{account_id}.json publisher specific categories for primary adserver
func NewFileFetcher(directory string) (stored_requests.AllFetcher, error) {
_, err := ioutil.ReadDir(directory)
if err != nil {
if _, err := ioutil.ReadDir(directory); err != nil {
return &fileFetcher{}, err
}
return &fileFetcher{
Expand Down
3 changes: 2 additions & 1 deletion stored_requests/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func resolvedStoredRequestsConfig(cfg *config.Configuration) (auc, amp config.St
// Auction endpoint uses non-Amp fields so can just copy the slin data
auc.Files.Enabled = sr.Files
auc.Files.Path = sr.Path
auc.Files.LazyLoad = sr.LazyLoad
auc.Files.LazyLoad = sr.FilesLazyLoad
auc.Postgres.ConnectionInfo = sr.Postgres.ConnectionInfo
auc.Postgres.FetcherQueries.QueryTemplate = sr.Postgres.FetcherQueries.QueryTemplate
auc.Postgres.CacheInitialization.Timeout = sr.Postgres.CacheInitialization.Timeout
Expand Down Expand Up @@ -195,6 +195,7 @@ func newFetcher(cfg *config.StoredRequestsSlim, client *http.Client, db *sql.DB)
if cfg.Files.Enabled {
fFetcher := newFilesystem(cfg.Files.Path)
if !cfg.Files.LazyLoad {
// Permanently load all categories in fetcher's internal static map
fFetcher.(stored_requests.CategoryFetcher).FetchAllCategories(context.Background())
}
idList = append(idList, fFetcher)
Expand Down

0 comments on commit ee1c30e

Please sign in to comment.