Skip to content

Commit 5b096f2

Browse files
committed
perf(serverHandler): skip some steps if auth failed
If auth failed, then: - skip state index file - skip merge alias
1 parent d51043a commit 5b096f2

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/serverHandler/archive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (h *handler) visitTreeNode(
9696
}
9797

9898
if fInfo.IsDir() {
99-
childInfos, _, _ := h.mergeAlias(rawReqPath, fInfo, childInfos)
99+
childInfos, _, _ := h.mergeAlias(rawReqPath, fInfo, childInfos, true)
100100
childInfos = h.FilterItems(childInfos)
101101

102102
// childInfo can be regular dir/file, or aliased item that shadows regular dir/file

src/serverHandler/responseData.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ func (h *handler) mergeAlias(
135135
rawRequestPath string,
136136
item os.FileInfo,
137137
subItems []os.FileInfo,
138+
doMerge bool,
138139
) (mergedSubItems, aliasSubItems []os.FileInfo, errs []error) {
139140
errs = []error{}
140141

141-
if (item != nil && !item.IsDir()) || len(h.aliases) == 0 {
142+
if !doMerge || (item != nil && !item.IsDir()) || len(h.aliases) == 0 {
142143
return subItems, nil, errs
143144
}
144145

@@ -223,8 +224,8 @@ func getStatusByErr(err error) int {
223224
}
224225
}
225226

226-
func (h *handler) stateIndexFile(rawReqPath, baseDir string, baseItem os.FileInfo) (file *os.File, item os.FileInfo, err error) {
227-
if len(h.dirIndexes) == 0 {
227+
func (h *handler) statIndexFile(rawReqPath, baseDir string, baseItem os.FileInfo, doStat bool) (file *os.File, item os.FileInfo, err error) {
228+
if !doStat || len(h.dirIndexes) == 0 {
228229
return
229230
}
230231

@@ -326,7 +327,7 @@ func (h *handler) getResponseData(r *http.Request) *responseData {
326327
status = getStatusByErr(_statErr)
327328
}
328329

329-
indexFile, indexItem, _statIdxErr := h.stateIndexFile(rawReqPath, reqFsPath, item)
330+
indexFile, indexItem, _statIdxErr := h.statIndexFile(rawReqPath, reqFsPath, item, authSuccess)
330331
if _statIdxErr != nil {
331332
errs = append(errs, _statIdxErr)
332333
status = getStatusByErr(_statIdxErr)
@@ -348,7 +349,7 @@ func (h *handler) getResponseData(r *http.Request) *responseData {
348349
status = http.StatusInternalServerError
349350
}
350351

351-
subItems, aliasSubItems, _mergeErrs := h.mergeAlias(rawReqPath, item, subItems)
352+
subItems, aliasSubItems, _mergeErrs := h.mergeAlias(rawReqPath, item, subItems, authSuccess)
352353
if len(_mergeErrs) > 0 {
353354
errs = append(errs, _mergeErrs...)
354355
status = http.StatusInternalServerError

0 commit comments

Comments
 (0)