Skip to content

Optimization: Reuse existing Data Models in AnalyzerReport #3307

@lakshita10341

Description

@lakshita10341

Problem

Currently, the AnalyzerReport.create_data_model method creates a new BaseDataModel instance every time it is called, even if an identical data model already exists in the database. This leads to redundant data storage and unnecessary object creation.

There is an existing TODO in api_app/analyzers_manager/models.py highlighting this:

# TODO we don't need to actually crate a new object every time.
#  if the report is the same of the previous one, we can just link it

Proposed Solution

Modify create_data_model to:

  1. Construct the data model dictionary as usual.
  2. Query the database for an existing data model of the correct class that matches the fields in the dictionary.
  3. If a match is found, reuse the existing object.
  4. If no match is found, proceed to create a new one.

I would like to work on it. Please let me know if there are any changes needed for this approach.

Metadata

Metadata

Assignees

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