-
-
Notifications
You must be signed in to change notification settings - Fork 282
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: reload product to fetch the language text #4717
Conversation
Hi @LuanRoger! The problem with your solution is that the product on the carousel is still in the previous language. |
11faeaa
to
f5d88c6
Compare
Every time that the user update the language it will get ALL the products on the local database and update them using the Does look good, @g123k? |
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 @LuanRoger!
I guess your code would work, but with very problematic side-effects:
- you load the whole product database in memory, and that would probably crash the app and/or be very slow (especially with the "offline: pre-download top 10K products"). A solution would be to load only the barcodes.
- each time the user changes the language, you synchronously download all the relevant products from the server. Which means that it does not work without connection, with a low connection and even with a normal connection (as it will take a while with the user waiting on a frozen drop-down selector UI). A solution would be to use background tasks instead.
Hello @monsieurtanuki Considering what you said on #4941 too, here my thoughts for possible solutions: Smart fetchThe local database stores every product the user saw, so those are not important to fetch at first or even never, since the local DB also stores the products that the user find thrugh the search for example, which many of the users never will look for them again. So instead of refresh all the products (considering the possible feature of slow bulks), refresh the ones in the user's created lists. For those is not in any list, the user continue to have the the manual refresh ( Refresh last accesed productsI'm not familiar with the code base yet, I does't found any information about the last products accessed by the user on Future<Map<String, Product>> getLast(int lasts) async {
final Map<String, Product> result = <String, Product>{};
final List<Map<String, dynamic>> queryResults =
await localDatabase.database.query(
_TABLE_PRODUCT,
columns: _columns,
orderBy: '$_TABLE_PRODUCT_COLUMN_LAST_UPDATE DESC',
limit: lasts,
);
for (final Map<String, dynamic> row in queryResults) {
result[row[_TABLE_PRODUCT_COLUMN_BARCODE] as String] =
_getProductFromQueryResult(row);
}
return result;
} But as I said, the In offlineIf the user change the language (or try to refresh the products in other way) while offline? Well, a possible solution could a kind flag, if the user try to refresh some product, the flag become Others considerations
I didn't realize that 😅, I will fix that as soon as possible.
Yes! I would consider that as a UX improvement, becaouse bofore implement that, is important to know whats need to be refreshed at first place, I think that, in the end, refresh all the products from the local database will not cause any major benefit. What you think? |
Indeed we have to prioritize which products to refresh. The most important are the products in the history, then the user lists, then the rest.
Indeed
The background tasks are not just a UX improvement, it's the only solution. The user cannot be stuck changing the language just because the connection is poor.
I'll PR this week about adding the language metadata ("the last time this product was downloaded, it was in Italian"). With this additional metadata, we can do things lazily:
Somehow, the step by step behavior would be similar to That said:
|
Ok them, so I'll be looking for some other issue to work with from time. Hope that you guys can fix this as soon as possible. It was a pleasure to help. |
@LuanRoger Thank you for your contribution: I will steal some of your suggestions ;) |
What
The product text is fetch from the server passing the current user language as parameter to it, so the server can return the appropriate text based on language. But the product is saved on a local database and the app get the product just if it doesn't exist.
This cause that the product text saved on the database may be on some other language, to avoid this to happen I redirect the user to
PRODUCT_LOADER
onpackages/smooth_app/lib/cards/product_cards/smooth_product_card_found.dart
(used on List tab), so every time that the user enter on product page it fetch from server (if possible).Remark
If the user do a manual refresh (via
RefreshIndicator
) the text is fixed.Fixes bug(s)