Skip to content

Dataset size and numberOfFiles becomes incorrect when dataset is created with initial values before OrigDatablock creation #2248

@Junjiequan

Description

@Junjiequan

Summary

The current implementation updates the dataset size incrementally when a new OrigDatablock is created:

    const createOrigDatablock: CreateOrigDatablockDto = {
      ...createDatasetOrigDatablockDto,
      datasetId: pid,
      ownerGroup: dataset.ownerGroup,
      accessGroups: dataset.accessGroups,
      instrumentGroup: dataset.instrumentGroup,
    };
    const datablock =
      await this.origDatablocksService.create(createOrigDatablock);

    const updateDatasetDto: PartialUpdateDatasetObsoleteDto = {
      size: dataset.size + datablock.size,
      numberOfFiles: dataset.numberOfFiles + datablock.dataFileList.length,
    };
    await this.datasetsService.findByIdAndUpdate(dataset.pid, updateDatasetDto);

This assumes that dataset.size and dataset.numberOfFiles always represent the sum of existing OrigDatablocks.

However, users can create a dataset with a predefined size and numberOfFiles before any OrigDatablock is created. When the first OrigDatablock is later added, the dataset values are incremented on top of the existing values, resulting in incorrect totals.

Steps to Reproduce

Create dataset

/api/v3/datasets
{
 ...otherfileds,
 size: 1000,
 numberOfFiles: 2
}

Create origDatablock

api/v3/datasets/:pid/origdatablocks
{
  ...otherfields,
   "dataFileList": [
    {
      "path": "string/string",
      "size": 1111,
      "time": "2026-03-04T09:37:02.960Z",
      "chk": "teststring",
    }
  ],

}

Current Behaviour

Fetch created dataset

api/v3/datasets/:pid

{
 ...otherfields,
 size: 2111,
 numberOfFiles:3
}

Expected Behaviour

Fetch created dataset

api/v3/datasets/:pid

{
 ...otherfields,
 size: 1111,
 numberOfFiles:1
}

Extra Details

Provide all the relevant details related to this issues. Include screenshot, wireframes and mockups if helpful.

PS: make ssure to add the proper tags to the issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions