@@ -103,9 +103,11 @@ const (
103
103
// Success status
104
104
Success = "success"
105
105
// GitConnector ...
106
- GitConnector = "git-connector"
107
- PackSize = 1000
108
- HotRepoCount = 50000
106
+ GitConnector = "git-connector"
107
+ PackSize = 1000
108
+ HotRepoCount = 50000
109
+ YearFirstHalf = "first-half"
110
+ YearSecondHalf = "second-half"
109
111
)
110
112
111
113
var (
@@ -524,16 +526,18 @@ var (
524
526
// GitTrailerPPAuthors - trailer name to authors map (for pair programming)
525
527
GitTrailerPPAuthors = map [string ]string {"Signed-off-by" : "authors_signed_off" , "Co-authored-by" : "co_authors" }
526
528
// max upstream date
527
- gMaxUpstreamDt time.Time
528
- gMaxUpstreamDtMtx = & sync.Mutex {}
529
- cachedCommits = make (map [string ]CommitCache )
530
- commitsCacheFile = "commits-cache.csv"
531
- createdCommits = make (map [string ]bool )
532
- IsHotRep = false
533
- CommitsByYearCacheFile = "commits-cache-%s.csv"
534
- CommitsUpdateCacheFile = "commits-update-cache.csv"
535
- CurrentCacheYear = 1970
536
- CachedCommitsUpdates = make (map [string ]CommitCache )
529
+ gMaxUpstreamDt time.Time
530
+ gMaxUpstreamDtMtx = & sync.Mutex {}
531
+ cachedCommits = make (map [string ]CommitCache )
532
+ commitsCacheFile = "commits-cache.csv"
533
+ createdCommits = make (map [string ]bool )
534
+ IsHotRep = false
535
+ CommitsByYearCacheFile = "commits-cache-%s.csv"
536
+ CommitsUpdateCacheFile = "commits-update-cache.csv"
537
+ CurrentCacheYear = 1970
538
+ CachedCommitsUpdates = make (map [string ]CommitCache )
539
+ CommitsByYearHalfCacheFile = "commits-cache-%s-%s.csv"
540
+ CurrentCacheYearHalf = YearFirstHalf
537
541
)
538
542
539
543
// Publisher - for streaming data to Kinesis
@@ -1869,7 +1873,7 @@ func (j *DSGit) GitEnrichItems(ctx *shared.Ctx, thrN int, items []interface{}, d
1869
1873
return
1870
1874
}
1871
1875
} else {
1872
- if err = j .createYearCacheFile (commits , path ); err != nil {
1876
+ if err = j .createYearHalfCacheFile (commits , path ); err != nil {
1873
1877
return
1874
1878
}
1875
1879
}
@@ -3160,7 +3164,10 @@ func (j *DSGit) SyncV2(ctx *shared.Ctx) (err error) {
3160
3164
if commitsCount >= HotRepoCount {
3161
3165
IsHotRep = true
3162
3166
CurrentCacheYear = from .Year ()
3163
- j .getYearCache (lastSync )
3167
+ if int (from .Month ()) > 6 {
3168
+ CurrentCacheYearHalf = YearSecondHalf
3169
+ }
3170
+ j .getYearHalfCache (lastSync )
3164
3171
j .getUpdateCache (lastSync )
3165
3172
} else {
3166
3173
j .getCache (lastSync )
@@ -3420,14 +3427,15 @@ func (j *DSGit) createCacheFile(cache []CommitCache, path string) error {
3420
3427
return nil
3421
3428
}
3422
3429
3423
- func (j * DSGit ) createYearCacheFile (cache []CommitCache , path string ) error {
3424
- nextYearCache := make ([]CommitCache , 0 )
3430
+ func (j * DSGit ) createYearHalfCacheFile (cache []CommitCache , path string ) error {
3431
+ nextYearHalfCache := make ([]CommitCache , 0 )
3425
3432
for _ , comm := range cache {
3426
3433
comm .FileLocation = path
3427
- if comm .CommitDate .Year () == CurrentCacheYear {
3434
+ commitYearHalf := getDateYearHalf (comm .CommitDate )
3435
+ if comm .CommitDate .Year () == CurrentCacheYear && commitYearHalf == CurrentCacheYearHalf {
3428
3436
cachedCommits [comm .EntityID ] = comm
3429
3437
} else {
3430
- nextYearCache = append (nextYearCache , comm )
3438
+ nextYearHalfCache = append (nextYearHalfCache , comm )
3431
3439
}
3432
3440
}
3433
3441
records := [][]string {
@@ -3438,7 +3446,7 @@ func (j *DSGit) createYearCacheFile(cache []CommitCache, path string) error {
3438
3446
}
3439
3447
3440
3448
yearSTR := strconv .Itoa (CurrentCacheYear )
3441
- cacheFile := fmt .Sprintf (CommitsByYearCacheFile , yearSTR )
3449
+ cacheFile := fmt .Sprintf (CommitsByYearHalfCacheFile , yearSTR , CurrentCacheYearHalf )
3442
3450
csvFile , err := os .Create (cacheFile )
3443
3451
if err != nil {
3444
3452
return err
@@ -3453,7 +3461,6 @@ func (j *DSGit) createYearCacheFile(cache []CommitCache, path string) error {
3453
3461
if err != nil {
3454
3462
return err
3455
3463
}
3456
- cachedCommits = make (map [string ]CommitCache )
3457
3464
err = j .cacheProvider .UpdateMultiPartFileByKey (j .endpoint , cacheFile )
3458
3465
if err != nil {
3459
3466
return err
@@ -3463,18 +3470,40 @@ func (j *DSGit) createYearCacheFile(cache []CommitCache, path string) error {
3463
3470
if err != nil {
3464
3471
return err
3465
3472
}
3466
- loadCacheToMemory ( records )
3467
- if len ( nextYearCache ) > 0 {
3468
- CurrentCacheYear = nextYearCache [0 ].CommitDate . Year ( )
3469
- if err = j .createYearCacheFile ( nextYearCache , path ); err != nil {
3473
+ if len ( nextYearHalfCache ) > 0 {
3474
+ //CurrentCacheYear = nextYearHalfCache[0].CommitDate.Year()
3475
+ updateYearHalf ( nextYearHalfCache [0 ].CommitDate )
3476
+ if err = j .createYearHalfCacheFile ( nextYearHalfCache , path ); err != nil {
3470
3477
return err
3471
3478
}
3472
3479
cachedCommits = make (map [string ]CommitCache )
3473
- j .getYearCache (os .Getenv ("LAST_SYNC" ))
3480
+ j .getYearHalfCache (os .Getenv ("LAST_SYNC" ))
3474
3481
}
3475
3482
return nil
3476
3483
}
3477
3484
3485
+ func getDateYearHalf (commitDate time.Time ) string {
3486
+ monthNumber := int (commitDate .Month ())
3487
+ if monthNumber > 6 {
3488
+ return YearSecondHalf
3489
+ }
3490
+ return YearFirstHalf
3491
+ }
3492
+
3493
+ func updateYearHalf (commitDate time.Time ) {
3494
+ cuHalf := getDateYearHalf (commitDate )
3495
+ if cuHalf == CurrentCacheYearHalf {
3496
+ return
3497
+ }
3498
+
3499
+ if CurrentCacheYearHalf == YearFirstHalf {
3500
+ CurrentCacheYearHalf = YearSecondHalf
3501
+ return
3502
+ }
3503
+ CurrentCacheYearHalf = YearFirstHalf
3504
+ CurrentCacheYear += 1
3505
+ }
3506
+
3478
3507
func (j * DSGit ) createUpdateCacheFile (cache []CommitCache , path string ) error {
3479
3508
for _ , comm := range cache {
3480
3509
comm .FileLocation = path
@@ -3631,9 +3660,9 @@ func (j *DSGit) getUpdateCache(lastSync string) {
3631
3660
}
3632
3661
}
3633
3662
3634
- func (j * DSGit ) getYearCache (lastSync string ) {
3663
+ func (j * DSGit ) getYearHalfCache (lastSync string ) {
3635
3664
yearSTR := strconv .Itoa (CurrentCacheYear )
3636
- commentBytes , err := j .cacheProvider .GetFileByKey (j .endpoint , fmt .Sprintf (CommitsByYearCacheFile , yearSTR ))
3665
+ commentBytes , err := j .cacheProvider .GetFileByKey (j .endpoint , fmt .Sprintf (CommitsByYearHalfCacheFile , yearSTR , CurrentCacheYearHalf ))
3637
3666
if err != nil {
3638
3667
return
3639
3668
}
0 commit comments