Skip to content

Refactor import blogs action#1

Open
jzmalik123 wants to merge 1 commit intoStaunchglobal:mainfrom
jzmalik123:refactor-import-blogs-action
Open

Refactor import blogs action#1
jzmalik123 wants to merge 1 commit intoStaunchglobal:mainfrom
jzmalik123:refactor-import-blogs-action

Conversation

@jzmalik123
Copy link

Changes Made

  • Removed transaction block
  • Used batch insertion to avoid database connection in each iteration
  • insert_all inserts multiple rows into the database in a single SQL statement, which is more efficient than creating each record individually.

Optimization Difference

  • Before optimization, the import action took around ~117 seconds to execute csv of 100k records.
    image

  • After optimization, the import action took around ~6 seconds to execute csv of 100k records.
    image

Result

  • The optimization made approximately 94% improvement in execution time.

Assumptions

  • The data in CSV is already validated and we don't need to handle validations while insertion
  • No external gems are allowed in optimisation

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

Successfully merging this pull request may close these issues.

1 participant