// To avoid caching issue, MRs are stripped of labels
To avoid caching issue, MRs are stripped of labels
// To avoid caching issue MRs are stripped of labels
func mrListWithCache(rn string, num int, opts gitlab.ListProjectMergeRequestsOptions) ([]*gitlab.MergeRequest, error) {
	bytes, err := json.Marshal(opts)
	if err != nil {
		lab.CmdLogger().Debugf("Cannot cache: %s", err)
		return lab.MRList(rn, opts, num)
	}
	rnBytes := []byte(rn)
	bytes = append(bytes, rnBytes...)
	hash := sha1.Sum(bytes)
	filename := fmt.Sprintf("ttl_5m/mr_list_%x.json", hash)
	lab.RemoveOldCacheEntries()
	inCache, bytes, err := lab.ReadCache(filename)
	if inCache && err == nil {
		var mrs []*gitlab.MergeRequest
		err := json.Unmarshal(bytes, &mrs)
		if err == nil {
			return mrs, nil
		} else {
			lab.CmdLogger().Debugf("Value found in cache, but cannot Unmarshal: %s", err)
		}
	}
	mrs, err := lab.MRList(rn, opts, num)
	if err != nil {
		return nil, err
	}
	for _, mr := range mrs {
		mr.Labels = nil
	}
	bytes, err = json.Marshal(mrs)
	if err == nil {
		lab.WriteCache(filename, bytes)
	} else {
		lab.CmdLogger().Debugf("Cannot write to cache: %s", err)
	}
	return mrs, err
}
func mrListWithCache ( rn string , num int , opts gitlab . ListProjectMergeRequestsOptions ) ( [ ] * gitlab . MergeRequest , error ) { bytes , err := json . Marshal ( opts ) if err != nil { lab . CmdLogger ( ) . Debugf ( " " , err ) return lab . MRList ( rn , opts , num ) } rnBytes := [ ] byte ( rn ) bytes = append ( bytes , rnBytes ... ) hash := sha1 . Sum ( bytes ) filename := fmt . Sprintf ( " " , hash ) lab . RemoveOldCacheEntries ( ) inCache , bytes , err := lab . ReadCache ( filename ) if inCache && err == nil { var mrs [ ] * gitlab . MergeRequest err := json . Unmarshal ( bytes , & mrs ) if err == nil { return mrs , nil } else { lab . CmdLogger ( ) . Debugf ( " " , err ) } } mrs , err := lab . MRList ( rn , opts , num ) if err != nil { return nil , err } for _ , mr := range mrs { mr . Labels = nil } bytes , err = json . Marshal ( mrs ) if err == nil { lab . WriteCache ( filename , bytes ) } else { lab . CmdLogger ( ) . Debugf ( " " , err ) } return mrs , err }
To avoid caching issue, MRs are stripped of labels
To avoid caching issue MRs are stripped of labels