Format URL for a specific shard Basically, remove start/end if is is before/after shard time
(uRL *url.URL, shardName int, startMonth int, endMonth int, timeRange *database.TimeRange)
| 648 | // Format URL for a specific shard |
| 649 | // Basically, remove start/end if is is before/after shard time |
| 650 | func formatURLForCache(uRL *url.URL, shardName int, startMonth int, endMonth int, timeRange *database.TimeRange) (string, error) { |
| 651 | // Extract URL query parameters |
| 652 | queryParams := uRL.Query() |
| 653 | |
| 654 | // Remove start |
| 655 | if startMonth < shardName { |
| 656 | queryParams.Del("start") |
| 657 | } |
| 658 | |
| 659 | // Remove start if timeRange.Start is the start of current month |
| 660 | if startMonth == shardName && isStartOfMonth(timeRange.Start) { |
| 661 | queryParams.Del("start") |
| 662 | } |
| 663 | |
| 664 | // Remove end |
| 665 | if endMonth > shardName { |
| 666 | queryParams.Del("end") |
| 667 | } |
| 668 | |
| 669 | // Remove cache for months before current month |
| 670 | currentMonth, err := shardNameToInt(timeToShardName(time.Now().UTC())) |
| 671 | if err != nil { |
| 672 | return "", err |
| 673 | } |
| 674 | |
| 675 | if shardName < currentMonth { |
| 676 | queryParams.Del("cache") |
| 677 | } |
| 678 | |
| 679 | // Add shard=shardName query parameter |
| 680 | queryParams.Add("shard", strconv.Itoa(shardName)) |
| 681 | |
| 682 | // Create new modified URL |
| 683 | cacheURL := *uRL |
| 684 | cacheURL.RawQuery = queryParams.Encode() |
| 685 | |
| 686 | return cacheURL.String(), nil |
| 687 | } |
| 688 | |
| 689 | func isStartOfMonth(t time.Time) bool { |
| 690 | y := t.Year() |
no test coverage detected