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

Adding getItemValuesById() method #42

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

urpizu
Copy link
Contributor

@urpizu urpizu commented Nov 29, 2018

A fast method to query the item values in a large database

@sp-philippe-oger
Copy link
Contributor

Why not using the original method getItemById, then simply create the array of values parsing the item?
I may have missed something, but it feels the library already covers this type of cases.

@sp-guillem-orpinell
Copy link

I tested in a 44K cells table (30 columns * 1300 rows), and it has a 20x better performance (from 21s to 1.1s). So it's a really convenient method when search performance matters!

@sp-philippe-oger
Copy link
Contributor

Just realized this is only a function and not a method of the Table object. I do not understand what it is supposed to do exactly. I can imagine how a binary search could speed things up in some cases, but I have difficulties to grasp the use for it here. An example would help?

The time you save is most likely because you're not creating a Sheetfu table. The index feature of the Sheetfu object is really fast, O(1), as those are literally lookups in hash tables (notorious for their speed), but it needs to have the Sheetfu table created.

@urpizu
Copy link
Contributor Author

urpizu commented Dec 3, 2018

Well... indeed, the main save is not creating the Sheetfu table. Basically, the function creates an array for the indexField column and it searches there. The trick saves 20x. Binary search it's not the main save (neither the purpose of the function).

I am using it particularly in the LiveOps Calendar Sidebar, so an abstraction of the use would be:
var table = Sheetfu.getTable(sheetName='table', headerRow=1); var id = selectedLiveOpsId(); var itemToAdd = Sheetfu.getItemValuesById(sheetName='database', headerRow=1, indexField='id', id); table.add(itemToAdd);

Even though it is not related to Table / Item, the arguments are following Sheetfu philosophy and the result (itemValues) easily integrable with other Sheetfu components (as .add() method)

@sp-philippe-oger
Copy link
Contributor

Since this is not part of Sheetfu Table scope, I feel this could create confusion to whoever uses the library, as we give 2 different ways to do the same thing.

We could keep it but it has to be much more documented in the code itself, and explain in which scenarios this solution is better than using the Table object.

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.

3 participants