feat: enhance CDN source management with last refreshed timestamp
Added functionality to track the last refreshed timestamp for CDN sources. Updated the database schema and relevant methods to include the last refreshed timestamp during creation and updates. Implemented logic to skip fetching CDN sources based on their refresh interval, improving efficiency in the module prefix collection process. Enhanced the data retrieval methods to support the new timestamp field, ensuring accurate state management for CDN sources.
This commit is contained in:
+16
-14
@@ -94,23 +94,25 @@ type ModulePatch struct {
|
||||
|
||||
// CDNSource is a row under a CDN module.
|
||||
type CDNSource struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
ModuleID string `json:"module_id,omitempty"`
|
||||
SourceKind string `json:"source_kind"`
|
||||
URL string `json:"url"`
|
||||
PrefixPath string `json:"prefix_path,omitempty"`
|
||||
Etag string `json:"etag"`
|
||||
RefreshIntervalSec *int `json:"refresh_interval_sec"`
|
||||
CommunityID *string `json:"community_id"`
|
||||
ID string `json:"id,omitempty"`
|
||||
ModuleID string `json:"module_id,omitempty"`
|
||||
SourceKind string `json:"source_kind"`
|
||||
URL string `json:"url"`
|
||||
PrefixPath string `json:"prefix_path,omitempty"`
|
||||
Etag string `json:"etag"`
|
||||
RefreshIntervalSec *int `json:"refresh_interval_sec"`
|
||||
CommunityID *string `json:"community_id"`
|
||||
LastRefreshedAt *time.Time `json:"-"`
|
||||
}
|
||||
|
||||
type CDNSourcePatch struct {
|
||||
SourceKind *string `json:"source_kind,omitempty"`
|
||||
URL *string `json:"url,omitempty"`
|
||||
PrefixPath *string `json:"prefix_path,omitempty"`
|
||||
Etag *string `json:"etag,omitempty"`
|
||||
RefreshIntervalSec *int `json:"refresh_interval_sec,omitempty"`
|
||||
CommunityID *string `json:"community_id,omitempty"`
|
||||
SourceKind *string `json:"source_kind,omitempty"`
|
||||
URL *string `json:"url,omitempty"`
|
||||
PrefixPath *string `json:"prefix_path,omitempty"`
|
||||
Etag *string `json:"etag,omitempty"`
|
||||
RefreshIntervalSec *int `json:"refresh_interval_sec,omitempty"`
|
||||
CommunityID *string `json:"community_id,omitempty"`
|
||||
LastRefreshedAt *time.Time `json:"-"`
|
||||
}
|
||||
|
||||
type ASEntry struct {
|
||||
|
||||
@@ -143,6 +143,7 @@ func (m *Memory) CreateCDNSource(tenantID, moduleID string, in *CDNSource) (*CDN
|
||||
Etag: in.Etag,
|
||||
RefreshIntervalSec: in.RefreshIntervalSec,
|
||||
CommunityID: in.CommunityID,
|
||||
LastRefreshedAt: in.LastRefreshedAt,
|
||||
}
|
||||
m.cdnSources[id] = s
|
||||
return s, nil
|
||||
@@ -184,6 +185,10 @@ func (m *Memory) UpdateCDNSource(tenantID, moduleID, sourceID string, patch *CDN
|
||||
s.CommunityID = &v
|
||||
}
|
||||
}
|
||||
if patch.LastRefreshedAt != nil {
|
||||
t := patch.LastRefreshedAt.UTC()
|
||||
s.LastRefreshedAt = &t
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user