@@ -3429,7 +3429,7 @@ func (j *DSGit) createCacheFile(cache []CommitCache, path string) error {
34293429 return nil
34303430}
34313431
3432- func (j * DSGit ) createYearHalfCacheFile (cache []CommitCache , path string ) error {
3432+ func (j * DSGit ) createYearHalfCacheFileOld (cache []CommitCache , path string ) error {
34333433 nextYearHalfCache := make ([]CommitCache , 0 )
34343434 currentYearCommitsCount := 0
34353435 for _ , comm := range cache {
@@ -3494,6 +3494,80 @@ func (j *DSGit) createYearHalfCacheFile(cache []CommitCache, path string) error
34943494 return nil
34953495}
34963496
3497+ func (j * DSGit ) createYearHalfCacheFile (cache []CommitCache , path string ) error {
3498+ nextYearHalfCache := make ([]CommitCache , 0 )
3499+ for _ , comm := range cache {
3500+ comm .FileLocation = path
3501+ commitYearHalf := getDateYearHalf (comm .CommitDate )
3502+ if comm .CommitDate .Year () == CurrentCacheYear && commitYearHalf == CurrentCacheYearHalf {
3503+ cachedCommits [comm .EntityID ] = comm
3504+ } else {
3505+ nextYearHalfCache = append (nextYearHalfCache , comm )
3506+ }
3507+ }
3508+
3509+ if err := j .syncRemoteCurrentYearCache (); err != nil {
3510+ return err
3511+ }
3512+
3513+ if len (nextYearHalfCache ) > 0 {
3514+ CurrentCacheYear = nextYearHalfCache [0 ].CommitDate .Year ()
3515+ CurrentCacheYearHalf = YearFirstHalf
3516+ if nextYearHalfCache [0 ].CommitDate .Month () > 6 {
3517+ CurrentCacheYearHalf = YearSecondHalf
3518+ }
3519+
3520+ j .getYearHalfCache (os .Getenv ("LAST_SYNC" ))
3521+ for _ , comm := range nextYearHalfCache {
3522+ comm .FileLocation = path
3523+ cachedCommits [comm .EntityID ] = comm
3524+ }
3525+
3526+ if err := j .syncRemoteCurrentYearCache (); err != nil {
3527+ return err
3528+ }
3529+ }
3530+
3531+ return nil
3532+ }
3533+
3534+ func (j * DSGit ) syncRemoteCurrentYearCache () error {
3535+ records := [][]string {
3536+ {"timestamp" , "entity_id" , "source_entity_id" , "file_location" , "hash" , "orphaned" , "from_dl" , "content" },
3537+ }
3538+ for _ , c := range cachedCommits {
3539+ records = append (records , []string {c .Timestamp , c .EntityID , c .SourceEntityID , c .FileLocation , c .Hash , strconv .FormatBool (c .Orphaned ), strconv .FormatBool (c .FromDL ), c .Content })
3540+ }
3541+
3542+ yearSTR := strconv .Itoa (CurrentCacheYear )
3543+ cacheFile := fmt .Sprintf (CommitsByYearHalfCacheFile , yearSTR , CurrentCacheYearHalf )
3544+ csvFile , err := os .Create (cacheFile )
3545+ if err != nil {
3546+ return err
3547+ }
3548+
3549+ w := csv .NewWriter (csvFile )
3550+ err = w .WriteAll (records )
3551+ if err != nil {
3552+ return err
3553+ }
3554+ err = csvFile .Close ()
3555+ if err != nil {
3556+ return err
3557+ }
3558+ err = j .cacheProvider .UpdateMultiPartFileByKey (j .endpoint , cacheFile )
3559+ if err != nil {
3560+ return err
3561+ }
3562+
3563+ err = os .Remove (cacheFile )
3564+ if err != nil {
3565+ return err
3566+ }
3567+
3568+ return nil
3569+ }
3570+
34973571func getDateYearHalf (commitDate time.Time ) string {
34983572 monthNumber := int (commitDate .Month ())
34993573 if monthNumber > 6 {
0 commit comments