Skip to content

Item CSV Import Update and Optimizations - #2821

Closed
objecttothis wants to merge 55 commits into
masterfrom
item_import_update
Closed

objecttothis wants to merge 55 commits into
masterfrom
item_import_update

Conversation

@objecttothis

Copy link
Copy Markdown
Member

No description provided.

@objecttothis objecttothis added this to the 3.4.0 milestone May 6, 2020
@objecttothis objecttothis self-assigned this May 6, 2020
@objecttothis

Copy link
Copy Markdown
Member Author

With these first two commits the update is working for base item data but not yet for updating attribute values. Still working on that, but so far this feature has been far easier than I thought it would be.

@objecttothis

Copy link
Copy Markdown
Member Author

@opensourcepos/org OK, I've got attributes updating. I begin testing tomorrow to make sure everything is in place. Feel free to play with it on the demo until someone pushes a commit on another PR. If the CSV import has an item_id in it, then the parser treats it like an update and should only update columns that are not blank and valid data. Please let me know anyone manages to break it so that I can work on the bugs. This has to be air tight.

@jekkos

jekkos commented May 7, 2020 •

Copy link
Copy Markdown
Member

@objecttothis You probably hear me coming but I think the perfect way to test this kind of functionality is by adding some unit tests. Main challenge would be to stub out the db calls in this case, but it would be the easiest way to do some combinations of different types of inputs to see if the code behaves as expected. No obligations here, just an idea :)

@objecttothis

objecttothis commented May 7, 2020 •

Copy link
Copy Markdown
Member Author

@objecttothis You probably hear me coming but I think the perfect way to test this kind of functionality is by adding some unit tests. Main challenge would be to stub out the db calls in this case, but it would be the easiest way to do some combinations of different types of inputs to see if the code behaves as expected. No obligations here, just an idea :)

philosophically, I am 100% on board. This is a skillset that I need to learn and it would help the code. The dilemma that I'm in is that because of the quarantine, our bookstore has very few sales which means that getting the store eCommerce site up has become top priority. Every day that goes by for us, can mean the difference between our staff being out of work or not.

Honestly, I think we as an @opensourcepos/org should always be moving toward requiring good dev practices and unit testing is one of them (where applicable). I just need to figure out how that practically needs to play out in this situation... food on the table for our staff or unit tests. ;)

@objecttothis
objecttothis marked this pull request as ready for review May 7, 2020 09:00
@objecttothis

objecttothis commented May 7, 2020 •

Copy link
Copy Markdown
Member Author

@opensourcepos/org OK, I've done the bulk of the testing (and fixing the bugs). Please have a look. It should be functioning in the demo as soon as the Travis-CI build completes.

@objecttothis
objecttothis marked this pull request as ready for review May 7, 2020 09:50
@jekkos

jekkos commented May 7, 2020

Copy link
Copy Markdown
Member

@objecttothis You probably hear me coming but I think the perfect way to test this kind of functionality is by adding some unit tests. Main challenge would be to stub out the db calls in this case, but it would be the easiest way to do some combinations of different types of inputs to see if the code behaves as expected. No obligations here, just an idea :)

philosophically, I am 100% on board. This is a skillset that I need to learn and it would help the code. The dilemma that I'm in is that because of the quarantine, our bookstore has very few sales which means that getting the store eCommerce site up has become top priority. Every day that goes by for us, can mean the difference between our staff being out of work or not.

Honestly, I think we as an @opensourcepos/org should always be moving toward requiring good dev practices and unit testing is one of them (where applicable). I just need to figure out how that practically needs to play out in this situation... food on the table for our staff or unit tests. ;)

Of course I understand you need to keep going, I appreciate that you're making the effort to go through the designs here with us (as I guess it's benefical to all in the end).

@daN4cat

daN4cat commented May 7, 2020

Copy link
Copy Markdown
Collaborator

@objecttothis please focus on your online store. Consider Shopify as an option. I've overhauled my wife's online shop with Shopify right as the lockdown started. The lockdown will last two to three months at least. We are all still in it here in London.

@objecttothis

Copy link
Copy Markdown
Member Author

@objecttothis please focus on your online store. Consider Shopify as an option. I've overhauled my wife's online shop with Shopify right as the lockdown started. The lockdown will last two to three months at least. We are all still in it here in London.

Thank you. Right now all the pull requests I am submitting here are to better get the data from OSPOS right and complete. I have another piece of software that will take ISBNs and scrape internet sites to pull all the metadata. This PR will allow me to then import that data into OSPOS which, with my CLCdesq API connector allow me to pump that data to the eCommerce site. Thanks for the recommendation on shopify. We have an inhouse CMS that another dev has been working on and I am just coming onboard with. It's C#/.NET so its a different animal, but RESTful APIs make that interaction a little easier.

@objecttothis objecttothis linked an issue May 8, 2020 that may be closed by this pull request
@objecttothis

Copy link
Copy Markdown
Member Author

@opensourcepos/org does anyone have any time to download this from bintray and see if they can break it? I believe it's working, but want to get a second set of eyes on the code and build.

@daN4cat

daN4cat commented Jun 4, 2020

Copy link
Copy Markdown
Collaborator

What's the status of this?

@objecttothis

Copy link
Copy Markdown
Member Author

What's the status of this?

It's what I'm working on finishing now. Unfortunately I am finding that it brings MySQL to it's knees because we have some significant inefficiencies. There are many columns being used in JOINs that are not indexed and many that are used in WHERE clauses that are not indexed. Since the update hits a lot of data in the database, it causes buffering problems. I'm working on finding the columns that aren't indexed. I've also needed to make some optimization changes by pulling queries outside of the foreach loop that have results that do not change and just pass the results in. I've also found a number of other places related where the code can use some optimization.

As an aside, this one is earmarked for 3.4.0 so don't let it hold up the release of 3.2.2.

@objecttothis objecttothis changed the title Item CSV Import Update Item CSV Import Update and Optimizations Jun 15, 2020
@objecttothis

Copy link
Copy Markdown
Member Author

@opensourcepos/org @daN4cat @jekkos This is ready for testing. In general, things should be snappier because of the added indexes and the changing of column types.

I recommend running mysqlcheck -u[username] -p -o [databasename] after the upgrade scripts run on the first login.

Major improvements:

  • speed of page loads, large reports and CSV import/update.
  • Ability to update items via CSV file if the item_id is provided. On rows where the item_id is not provided, it creates a new item.

Things that I've tested and need to be tested by anyone willing:

  • importing a CSV file to make sure updates are working properly and imports still work.
  • Basic usage of the application to make sure no regression has happened.
  • Test large detailed reports. Detailed Transactions report should be faster.

I was able to import 13,580 rows with 15-20avg number of attributes on each row and it did great. While I'm waiting for people to do code reviews @jekkos? @daN4cat? I'll see if I can get phpunit running and write unit tests (I know @jekkos will be happy).

- There was a bug in the code that caused attribute_link rows to be
duplicated with the same information on item_import with an update.
This migration removes the duplicate rows.
@jekkos

jekkos commented Nov 7, 2020

Copy link
Copy Markdown
Member

@objecttothis I hope all is still ok on your side and that the situation in your country is not affecting you too much.

But as 3.3.3 is near completion, I want to pick up your first PR here, but now see it might needs a refresh.

Would you mind to rebase this on latest master and perhaps squash some of the commits to make it more easy to review?

It might make our history log a bit cleaner.. unless you feel other reasons to have the whole commit history inlcuded? Thanks

@jekkos jekkos closed this Nov 7, 2020
@jekkos jekkos reopened this Nov 7, 2020
@objecttothis

Copy link
Copy Markdown
Member Author

@objecttothis I hope all is still ok on your side and that the situation in your country is not affecting you too much.

But as 3.3.3 is near completion, I want to pick up your first PR here, but now see it might needs a refresh.

Would you mind to rebase this on latest master and perhaps squash some of the commits to make it more easy to review?

It might make our history log a bit cleaner.. unless you feel other reasons to have the whole commit history inlcuded? Thanks

OK, I'll be working on this Tuesday when I'm back in the office.

objecttothis and others added 5 commits November 10, 2020 17:35
Changes not yet merged.

Rebase on master

Formatting Changes and optimization

Set all imported items to undeleted by default

Remove Duplicate links

- There was a bug in the code that caused attribute_link rows to be
duplicated with the same information on item_import with an update.
This migration removes the duplicate rows.

Fixed duplicate attribute_link bug

- In the event that an item was being updated and the new
attribute_value didn't exist, the old attribute_link was not being
deleted which caused two attribute_link rows to exist with the same
item_id and definition_id.

Bug Fix

- Corrected Saving of inventory quantities to allow 0 quantity to be
entered.

Rebase

Rebase

Fixing accidental revert

Rebase

Warning Fixes

Rebase on Master

Refactored function names

Added Indexes

- Three new indexes to fix a problem where item tables won't load with
large databases due to how long the query takes.

Formatting

- Removed Leading underscores from functions and variables
- Replaced " with ' where " was not necessary
- Removed unnecessary whitespace and blank lines
- Refactored variable names for clarity

Bug fixes and Formatting

- Fixed vertical indentation
- Removed item_id assignment from Items->view() which is causing new
items to get assigned string '-1' for item_id and confuses the save()
function.
- Assigned default item_id to NEW_ITEM for Items->attributes() function.
- Refactored variable name for readability.
- Extracted local variable for readability.
- Replaced " with ' where not needed.
- Removed unneeded comments
- Reworked importfile_helper->get_csv_file for speed and readability
- Reworked importfile_helper->bom_exists for readability
- unset large arrays and set to null when not needed for garbage
collection.
- Corrected bug in Attribute->value_exists to correctly return
attribute_id for attribute_date values that exist.
- Fixed a bug in Attribute->save_value that caused two different query
builders to be mixed when adding an attribute.
- Replaced == with === for speed and safety.
- Fixed position of " in daterangepicker

Fixed missing " in daterangepicker

Bug Fix

- Fixed bug in pic_thumb() where an error would be generated if you
tried to resize a file to something that already existed.  Added check
for a file name.

rebase actions

Bug Fixes and enhancements

- Switched == and != for === and !== where possible.
- Fixed indentation
- replaced . concatenation with " and variables inside quotes where
possible for readability.
- Replaced " with ' where not needed.
- Removed unneeded empty lines
- Fixed bug in locale_helper causing parse_decimals to return string '0'
when it should actually process it and return integer 0
- Corrected valid_date() in locale_helper to return based on the locale
chosen

Bug Fix

- Fixed a Bug causing DATE duplicate removal to fail when two items had
the same attribute_value

Bug Fixes

- Make data_error_check() error message for incorrect date match the
requirement for the import data to match the set date locale.

Formatting Fixes

Fixed variable name

Bug Fix

- Corrected bug that does not convert attribute dates to system selected
format which causes the save attribute logic to fail.

Formatting changes

Bug fixes

- Reverted some === to == unil unit tests could be written to confirm
they do not break things.
- Corrected value_exists function to properly check for date attributes
- Removed unused variables.
- Removed call to delete_orphaned_values because it is causing problems
- Fixed code formatting
- Removed trailing whitespace and whitespace on blank lines

Code Cleanup

- Removed unused variables
- Initialize variables that were not initialized before being used.
- Replaced " for ' in PHP where " was not needed.
- Replaced " for ' in HTML where possible for consistency.
- Fixed bug in Item-kit
- Fixed bug in Item->get_search_suggestions where a join was done
without specifying the table.
- corrected Item->get_kit_search_suggestions search_custom query to
actually query the attributes table rather than the deprecated and
removed custom fields.

Code formatting and cleanup

- Correcting &nbsp to  
- replacing " for ' for consistency in the code
- Removing trailing whitespace
- Removing whitespace on empty lines
- Removed unneeded comments
- corrected </div> to </textarea>

Fixed syntax error

Optimizations

- Replace array_push() with [].
- Rename Attribute->undelete() to Attribute->undelete_definition() for
consistency in naming conventions.
- Added call to delete_orphaned_values when an attribute_link row is
deleeted to prevent orphaned_value rows from forming.
- Clarified javadoc comments
- Removed trailing whitespace
- Removed whitespace on empty lines

Further optimization to CSV import

Additional formatting and bug fixes

Bug fixes

- Fixed a problem causing quantities to not be properly stored.
- Added a check to fail a line if an item_id is provided that does not
exist.

Resort query order

- Resorted order to take advantage of query indexes in the database.

Formatting and code cleanup

- Added NEW_ITEM constant
- Renamed variables for clarity
- Tab indentation of equals signs for easy of reading
- Removed unnecessary comments
- Removed unecessary variable.
- Renamed CSV headings to for consistency with other headings
- Remove method chaining for clarity.
- Replaced array() and new Array() with [] for speed (+20%) and to match
current standard.
- Removed trailing whitespace and whitespace on empty lines

Reverted Method Chaining changes

Requested changes and bug fixes

- Fixed a bug causing attribute conversion to fail.
- Code cleanup and optimization in the convert_definition_data method.
- Reverted method chaining in query builder methods for readability.
- Resorted Attribute model to original method order for clarity in code
review.

Optimization

- Cleaned up code
- Optimized out 1 query call per attribute per row in import file.

Added to Migration SQL

- Changed some columns from tinyint to tinyint(1)
- Removed from querybuilder calls to optimize speed.

Regression Fix

Rebase

Rebase

Rebase

Queries

Allow empty quantity field

Attribute import update fixes

- Corrected bug in Items->data_error_check preventing dates from being
checked properly.
- Fixed attribute save to properly account for decimal and date updates.

Update attribute values

Rebase on Master
…port_update

# Conflicts:
#	application/models/Sale.php
#	application/views/configs/system_info.php
#	application/views/partial/stock_locations.php
#	application/views/sales/quote_email.php
@objecttothis

Copy link
Copy Markdown
Member Author

@jekkos I rebased this branch on the master, but I have not been able to squash the commits together. I've tried it both with PHPStorm and Eclipse. PHPStorm is proving to be a lot easier to use than Eclipse, but it still would not squash commits. It gives me an error telling me that the commits I'm trying to squash have two parents. That said, the conflicts with the master have been resolved.

@jekkos

jekkos commented Nov 17, 2020

Copy link
Copy Markdown
Member

@objecttothis thank you for that already. I can try to do the squash for you.

@jekkos

jekkos commented Nov 23, 2020 •

Copy link
Copy Markdown
Member

@objecttothis I have squashed all work in one commit in item-import-update branch in this repo

Could you check out that branch and amend the commit so it has your name as author on it? I think there was a bit of an issue as indeed some of the commits had multiple parents and that made the rebase impossible to do.

So what I did basically was

  • Check out master branch and rename this to this branch name
  • Check out the files from the last version of your branch in this new branch
  • Commit those files to this branch.

Squashing commits has a couple of advantages

  • It's a lot easier to review
  • Git history is cleaner

But the downside is that you loose track of all the changes you actually did. However if the intention is to add just one feature, then in principle one commit per feature should be fine.

@jekkos

jekkos commented Nov 25, 2020

Copy link
Copy Markdown
Member

@objecttothis If you agree we can continue the review on #3029 ? You can check that one out, amend the commit so it carries your name and authorship?

@objecttothis

Copy link
Copy Markdown
Member Author

So sorry. I went on vacation this week and then got diagnosed with COVID-19 today. This kind of thing seems to happen every time I go on vacation. Yes please continue the code review on the other PR and I'll change the author on the commit.

@objecttothis

Copy link
Copy Markdown
Member Author

@objecttothis If you agree we can continue the review on #3029 ? You can check that one out, amend the commit so it carries your name and authorship?

OK, I changed the commit author on the other branch, so we can continue in that PR. The only difference is that PR is authored by @jekkos. I don't think that is an issue, because you can do a code review for your own PR, but if it is then the solution would be to keep the branch, close that PR (and this one) and then to have me create a PR with that branch. I did assign the PR that @jekkos authored to me though, so I should still get notifications.

@jekkos

jekkos commented Nov 25, 2020

Copy link
Copy Markdown
Member

Ok maybe you should reopen it then. You can close the one I created. Thanks.

@daN4cat

daN4cat commented Nov 25, 2020 •

Copy link
Copy Markdown
Collaborator

@objecttothis take care of yourself, unplug from here and get well soon. Don't underestimate covid-19 even if it looks a mild thing at the beginning.

@objecttothis

Copy link
Copy Markdown
Member Author

@daN4cat thanks. I'll be back from vacation on Tuesday. I'm already in the tail end of the virus. At it's worst I was sleeping for 14 hour chunks. Glad to be out of that.

@jekkos I don't mind you being the PR author. It has me as the commit author so that's fine. If someone wants to start a code review while I'm gone, that's fine.

@jekkos

jekkos commented Nov 26, 2020

Copy link
Copy Markdown
Member

@objecttothis If you agree we can continue the review on #3029 ? You can check that one out, amend the commit so it carries your name and authorship?

OK, I changed the commit author on the other branch, so we can continue in that PR. The only difference is that PR is authored by @jekkos. I don't think that is an issue, because you can do a code review for your own PR, but if it is then the solution would be to keep the branch, close that PR (and this one) and then to have me create a PR with that branch. I did assign the PR that @jekkos authored to me though, so I should still get notifications.

So sorry. I went on vacation this week and then got diagnosed with COVID-19 today. This kind of thing seems to happen every time I go on vacation. Yes please continue the code review on the other PR and I'll change the author on the commit.

@objecttothis take care as @daN4cat says....

@objecttothis

Copy link
Copy Markdown
Member Author

Closing this here since it's now being implemented in PR #3029

@objecttothis
objecttothis deleted the item_import_update branch January 12, 2021 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Import Item csv CSV Item Import Update mode

4 participants