-
-
Notifications
You must be signed in to change notification settings - Fork 287
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
fix: Offline product knowledge panel issue #2693
fix: Offline product knowledge panel issue #2693
Conversation
Co-authored-by: Abu Ghalib <abughalib@users.noreply.github.com>
…into offline-Product-Knowlege-Panel-Issue
…into offline-Product-Knowlege-Panel-Issue
Codecov Report
@@ Coverage Diff @@
## develop #2693 +/- ##
==========================================
- Coverage 8.86% 7.12% -1.75%
==========================================
Files 161 218 +57
Lines 6623 10645 +4022
==========================================
+ Hits 587 758 +171
- Misses 6036 9887 +3851
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @AshAman999!
Not 100% convinced: please have a look at my comments.
await daoProduct.getAll(allProductCodes); | ||
allProducts.removeWhere( | ||
(String key, Product value) => value.knowledgePanels == null); | ||
allProductCodes = allProducts.keys.toList(); | ||
final List<ProductField> fields = ProductQuery.fields; | ||
fields.remove(ProductField.KNOWLEDGE_PANELS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually that's not OK: you're also removing an item from the main fields
.
You should copy all the fields you need instead, into your own list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had done a for each
iteration but as a left suggestion I changed it
Might be something like this would work fine
final List<String> allProductCodes = await daoProduct.getAllKeys();
final Map<String, Product> allProducts =
await daoProduct.getAll(allProductCodes);
allProducts.forEach((String code, Product product) {
if (product.knowledgePanels != null) {
allProductCodes.remove(code);
}
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You haven't implemented a fix, have you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I did the changes that you asked about not loading all the products
final Map<String, Product> allProducts = | ||
await daoProduct.getAll(allProductCodes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That means you're loading ALL the database.
I know it's only for dev mode, but that's not something I would recommend.
What about getting all the barcodes instead of barcodes AND products.
For the level of granularity we want that's good enough I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@monsieurtanuki
Just to clarify, this is not always supposed to be in dev mode, after further fine-tuning and doing this task in background, we are probably thinking of showing a menu in onboarding screens to let preload data, but not just 100o, rather in numbers of 10k.
And why I loaded the products as well is because there is no way where I can be sure that which barcodes will have knowledge panels or not. I tried thinking of alternate solutions even using daoproductlist
, would be helpful for me to get an alternate idea to do the same without loading all the products but with just the barcode strings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess a SQL query for getting all the barcode with Products having knowledge panel
could have probably helped here.
But since we already don't do much of magic with SQL, can't say what else we can do here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DaoProduct.getAllKeys()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I get all the keys now I updated the database with top 1000 products
Now, if I do again try to get the top 1000 products, just for sense of updating it,
When I do DaoProduct.getAllKeys()
, I will get the list of barcodes along with the top 1000 products, so now the list of barcodes will have more than 1000, and hence I can't update it. Ryt?
I hope now you can understand the problem...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I skipped that one:
Just to clarify, this is not always supposed to be in dev mode, after further fine-tuning and doing this task in background, we are probably thinking of showing a menu in onboarding screens to let preload data, but not just 100o, rather in numbers of 10k.
But now we're on dev mode, so let's focus on that. Background task later.
Regarding putting that in onboarding, that's a bold move considering the current popularity of the onboarding among the users.
Regarding 10K bulk load, I don't see how you can skip the "download first, then refresh locally if relevant, then the next 10K" for the whole server data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@monsieurtanuki
About your query to not load all products to check if they have knowledge panels or not
What I propose is we add another column in the table with name "isHalfProduct"
, and we give it a default value of false
And when pushing a product to db, we can say that it is not fully downloaded by just passing an argument as true.
Would be best if you could suggest me if I should go ahead with this approach??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I propose is we add another column in the table with name
"isHalfProduct"
, and we give it a default value of false
I don't think it's a good idea to add computed columns to sqflite
. In general that's a pain in the neck to add columns: not just adding them, but then initializing them, and keep the init script running forever, and then you add another column and you wind up with several scripts that run forever.
Especially in this case: there's not such thing as isHalfProduct
. Unless that means "null knowledge panels" on August 5th, 2022. But what next?
My suggestion: you only have to code a single method that will solve all your problems. And luckily, that's easy to code, and to test as a background method:
- 2 parameters,
DaoProduct
andProduct newProduct
- you try to get from
DaoProduct
aProduct
withbarcode = newProduct.barcode!
- if there's indeed already one product, you check its
knowledgePanels
field. If it's not null, you returnfalse
(that's data that you don't want to overwrite) - else you upsert your
newProduct
and returntrue
(that's data that either did not exist locally, or that didn't include kwowledge panels so your new version is better)
Et voilà.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done that, plz re review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping @monsieurtanuki
Co-authored-by: monsieurtanuki <fabrice_fontaine@hotmail.com>
…into offline-Product-Knowlege-Panel-Issue
….com/AshAman999/smooth-app into offline-Product-Knowlege-Panel-Issue
…into offline-Product-Knowlege-Panel-Issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @AshAman999!
My main concern is about ProductQuery.fields
field that you alter.
Please make ProductQuery.fields
a static const
.
await daoProduct.getAll(allProductCodes); | ||
allProducts.removeWhere( | ||
(String key, Product value) => value.knowledgePanels == null); | ||
allProductCodes = allProducts.keys.toList(); | ||
final List<ProductField> fields = ProductQuery.fields; | ||
fields.remove(ProductField.KNOWLEDGE_PANELS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You haven't implemented a fix, have you?
@monsieurtanuki |
…into offline-Product-Knowlege-Panel-Issue
@AshAman999 I'm afraid you're right. |
I did most of the changes you suggested me here, If we could merge it, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me @AshAman999
can I merge @AshAman999 @monsieurtanuki ? |
Now it's good to go !!! |
🎉 |
What
products with KP
when preloading dataFixes bug(s)
Part of