Skip to content

Commit f1ac51e

Browse files
authored
Refs #2144, remove calcCacheMu field in the File data structure (#1440)
- Increase unit test time out to 1 hour
1 parent 8990800 commit f1ac51e

File tree

9 files changed

+15
-33
lines changed

9 files changed

+15
-33
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
GOARCH=arm64 GOOS=android go build .
3939
4040
- name: Test
41-
run: env GO111MODULE=on go test -v -timeout 50m -race ./... -coverprofile='coverage.txt' -covermode=atomic
41+
run: env GO111MODULE=on go test -v -timeout 60m -race ./... -coverprofile='coverage.txt' -covermode=atomic
4242

4343
- name: Codecov
4444
uses: codecov/codecov-action@v5

adjust.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (f *File) adjustHelper(sheet string, dir adjustDirection, num, offset int)
7575
if err != nil {
7676
return err
7777
}
78-
f.clearCalcCache()
78+
f.calcCache.Clear()
7979
sheetID := f.getSheetID(sheet)
8080
if dir == rows {
8181
err = f.adjustRowDimensions(sheet, ws, num, offset)

calc.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -840,13 +840,9 @@ type formulaFuncs struct {
840840
// ZTEST
841841
func (f *File) CalcCellValue(sheet, cell string, opts ...Options) (result string, err error) {
842842
cacheKey := fmt.Sprintf("%s!%s", sheet, cell)
843-
f.calcCacheMu.RLock()
844843
if cachedResult, found := f.calcCache.Load(cacheKey); found {
845-
f.calcCacheMu.RUnlock()
846844
return cachedResult.(string), nil
847845
}
848-
f.calcCacheMu.RUnlock()
849-
850846
options := f.getOptions(opts...)
851847
var (
852848
rawCellValue = options.RawCellValue
@@ -870,27 +866,21 @@ func (f *File) CalcCellValue(sheet, cell string, opts ...Options) (result string
870866
if precision > 15 {
871867
result, err = f.formattedValue(&xlsxC{S: styleIdx, V: strings.ToUpper(strconv.FormatFloat(decimal, 'G', 15, 64))}, rawCellValue, CellTypeNumber)
872868
if err == nil {
873-
f.calcCacheMu.Lock()
874869
f.calcCache.Store(cacheKey, result)
875-
f.calcCacheMu.Unlock()
876870
}
877871
return
878872
}
879873
if !strings.HasPrefix(result, "0") {
880874
result, err = f.formattedValue(&xlsxC{S: styleIdx, V: strings.ToUpper(strconv.FormatFloat(decimal, 'f', -1, 64))}, rawCellValue, CellTypeNumber)
881875
}
882876
if err == nil {
883-
f.calcCacheMu.Lock()
884877
f.calcCache.Store(cacheKey, result)
885-
f.calcCacheMu.Unlock()
886878
}
887879
return
888880
}
889881
result, err = f.formattedValue(&xlsxC{S: styleIdx, V: token.Value()}, rawCellValue, CellTypeInlineString)
890882
if err == nil {
891-
f.calcCacheMu.Lock()
892883
f.calcCache.Store(cacheKey, result)
893-
f.calcCacheMu.Unlock()
894884
}
895885
return
896886
}
@@ -1335,13 +1325,6 @@ func calcDiv(rOpd, lOpd formulaArg, opdStack *Stack) error {
13351325
return nil
13361326
}
13371327

1338-
// clearCalcCache clear all calculation cache.
1339-
func (f *File) clearCalcCache() {
1340-
f.calcCacheMu.Lock()
1341-
f.calcCache.Clear()
1342-
f.calcCacheMu.Unlock()
1343-
}
1344-
13451328
// calculate evaluate basic arithmetic operations.
13461329
func calculate(opdStack *Stack, opt efp.Token) error {
13471330
if opt.TValue == "-" && opt.TType == efp.TokenTypeOperatorPrefix {

cell.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func (c *xlsxC) hasValue() bool {
182182

183183
// removeFormula delete formula for the cell.
184184
func (f *File) removeFormula(c *xlsxC, ws *xlsxWorksheet, sheet string) error {
185-
f.clearCalcCache()
185+
f.calcCache.Clear()
186186
if c.F != nil && c.Vm == nil {
187187
sheetID := f.getSheetID(sheet)
188188
if err := f.deleteCalcChain(sheetID, c.R); err != nil {
@@ -795,7 +795,7 @@ func (f *File) SetCellFormula(sheet, cell, formula string, opts ...FormulaOpts)
795795
if err != nil {
796796
return err
797797
}
798-
f.clearCalcCache()
798+
f.calcCache.Clear()
799799
if formula == "" {
800800
ws.deleteSharedFormula(c)
801801
c.F = nil
@@ -1371,7 +1371,7 @@ func (f *File) SetCellRichText(sheet, cell string, runs []RichTextRun) error {
13711371
if si.R, err = setRichText(runs); err != nil {
13721372
return err
13731373
}
1374-
f.clearCalcCache()
1374+
f.calcCache.Clear()
13751375
for idx, strItem := range sst.SI {
13761376
if reflect.DeepEqual(strItem, si) {
13771377
c.T, c.V = "s", strconv.Itoa(idx)

excelize.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ type File struct {
4242
tempFiles sync.Map
4343
xmlAttr sync.Map
4444
calcCache sync.Map
45-
calcCacheMu sync.RWMutex
4645
CalcChain *xlsxCalcChain
4746
CharsetReader func(charset string, input io.Reader) (rdr io.Reader, err error)
4847
Comments map[string]*xlsxComments

merge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (f *File) UnmergeCell(sheet, topLeftCell, bottomRightCell string) error {
115115
if err = ws.mergeOverlapCells(); err != nil {
116116
return err
117117
}
118-
f.clearCalcCache()
118+
f.calcCache.Clear()
119119
i := 0
120120
for _, mergeCell := range ws.MergeCells.Cells {
121121
if rect2, _ := rangeRefToCoordinates(mergeCell.Ref); isOverlap(rect1, rect2) {

pivotTable.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func (f *File) AddPivotTable(opts *PivotTableOptions) error {
163163
if err != nil {
164164
return err
165165
}
166-
f.clearCalcCache()
166+
f.calcCache.Clear()
167167
pivotTableID := f.countPivotTables() + 1
168168
pivotCacheID := f.countPivotCache() + 1
169169

@@ -1062,7 +1062,7 @@ func (f *File) DeletePivotTable(sheet, name string) error {
10621062
if err != nil {
10631063
return err
10641064
}
1065-
f.clearCalcCache()
1065+
f.calcCache.Clear()
10661066
pivotTableCaches := map[string]int{}
10671067
pivotTables, _ := f.getPivotTables()
10681068
for _, sheetPivotTables := range pivotTables {

sheet.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ func (f *File) SetSheetName(source, target string) error {
384384
if target == source {
385385
return err
386386
}
387-
f.clearCalcCache()
387+
f.calcCache.Clear()
388388
wb, _ := f.workbookReader()
389389
for k, v := range wb.Sheets.Sheet {
390390
if v.Name == source {
@@ -580,7 +580,7 @@ func (f *File) DeleteSheet(sheet string) error {
580580
if idx, _ := f.GetSheetIndex(sheet); f.SheetCount == 1 || idx == -1 {
581581
return nil
582582
}
583-
f.clearCalcCache()
583+
f.calcCache.Clear()
584584
wb, _ := f.workbookReader()
585585
wbRels, _ := f.relsReader(f.getWorkbookRelsPath())
586586
activeSheetName := f.GetSheetName(f.GetActiveSheetIndex())
@@ -769,7 +769,7 @@ func (f *File) copySheet(from, to int) error {
769769
if err != nil {
770770
return err
771771
}
772-
f.clearCalcCache()
772+
f.calcCache.Clear()
773773
worksheet := &xlsxWorksheet{}
774774
deepcopy.Copy(worksheet, sheet)
775775
toSheetID := strconv.Itoa(f.getSheetID(f.GetSheetName(to)))
@@ -1773,7 +1773,7 @@ func (f *File) SetDefinedName(definedName *DefinedName) error {
17731773
if err != nil {
17741774
return err
17751775
}
1776-
f.clearCalcCache()
1776+
f.calcCache.Clear()
17771777
d := xlsxDefinedName{
17781778
Name: definedName.Name,
17791779
Comment: definedName.Comment,
@@ -1816,7 +1816,7 @@ func (f *File) DeleteDefinedName(definedName *DefinedName) error {
18161816
if err != nil {
18171817
return err
18181818
}
1819-
f.clearCalcCache()
1819+
f.calcCache.Clear()
18201820
if wb.DefinedNames != nil {
18211821
for idx, dn := range wb.DefinedNames.DefinedName {
18221822
scope := "Workbook"

table.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (f *File) AddTable(sheet string, table *Table) error {
118118
return err
119119
}
120120
f.addSheetNameSpace(sheet, SourceRelationship)
121-
f.clearCalcCache()
121+
f.calcCache.Clear()
122122
if err = f.addTable(sheet, tableXML, coordinates[0], coordinates[1], coordinates[2], coordinates[3], tableID, options); err != nil {
123123
return err
124124
}
@@ -178,7 +178,7 @@ func (f *File) DeleteTable(name string) error {
178178
if err != nil {
179179
return err
180180
}
181-
f.clearCalcCache()
181+
f.calcCache.Clear()
182182
for sheet, tables := range tbls {
183183
for _, table := range tables {
184184
if table.Name != name {

0 commit comments

Comments
 (0)