Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bucketManager.listPrefix 查询结果不准确 #377

Open
jianhao opened this issue Mar 30, 2021 · 0 comments
Open

bucketManager.listPrefix 查询结果不准确 #377

jianhao opened this issue Mar 30, 2021 · 0 comments

Comments

@jianhao
Copy link

jianhao commented Mar 30, 2021

我使用bucketManager.listPrefix方法查询空间里符合前缀条件的文件列表,但是在参数一样的前提下,偶现查询结果不准确的场景。

查询代码如下:

  /**
   * 根据分页信息和前缀获取文件列表
   * @param query
   */
  async queryFiles (query) {
    const { prefix = 'monitoring/assets/', pageNo, pageSize } = query || {}
    const options = {
      limit: 10000, // 每次返回的文件数量上限
      prefix,
    }
    const findFiles = new Promise((resolve, reject) => {
      bucketManager.listPrefix(bucket, options, (err, respBody, respInfo) => {
        if (err) {
          console.log('查询失败', err)
          throw err
        }
        const { marker } = respBody
        console.log(marker, prefix, pageNo, pageSize)
        if (respInfo.statusCode === 200) {
          // 因为 pageNo 是从 1 开始的所以简单做下分页
          const newItems = respBody?.items.sort((a, b) => b?.putTime - a?.putTime)
          const data = newItems?.slice((pageNo - 1) * pageSize, pageNo * pageSize)
          const response = {
            data: data || [],
            pageSize: Number(pageSize) || 0,
            pageNo: Number(pageNo) || 0,
            total: respBody?.items?.length || 0,
          }
          resolve(response)
        } else {
          reject(respInfo)
        }
      })
    })
    const result: any = await findFiles
    return result
  }

查询结果如下:
异常情况:
image

正常情况:
image

传入的bucket一直为空, options不变,得到的结果很奇怪,而且我去七牛官方查看我空间的文件列表,发现也出现查询接口返回为空的情况。

异常结果:

image

正常情况:
image

所以请问这查询是有问题么,还是我哪里姿势不对?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant