<commit_before>import co from 'co'
import { EmagTrackerAPI } from "../../backend"
import { StorageAPI } from "../../storage"
import { NotificationsAPI } from "../../notifications"

/**
 * Load user products from remote or local if not available
 */
export const load = (onlineData, allowNotifications) =>
    StorageAPI
        .getSync(null)
        .then(items => {
            delete items.lastCheck
            delete items.settings
            if ($.isEmptyObject(items)) {
                // show some text - no products marked yet
                return Promise.reject("No products tracked yet")
            } else {
                return co(function* () {
                        const products = []
                        for (let pid of Object.getOwnPropertyNames(items)) {
                            let product = {}
                            if (onlineData) {
                                product = yield EmagTrackerAPI.getProduct(pid)
                            }
                            if ($.isEmptyObject(product)) {
                                if (onlineData)
                                    console.warn("Remote fetch failed for pid=" + pid + ". Attempting to load from local.")
                                product = yield StorageAPI.getLocal(pid)
                                if (allowNotifications && $.isEmptyObject(product))
                                    NotificationsAPI.error("Could not find product " + pid)
                                else
                                    products.push(product)
                            } else
                                products.push(product)
                        }
                        return products
                    })
            }
        })<commit_msg>bugfix load offline products<commit_after>import co from 'co'
import { EmagTrackerAPI } from "../../backend"
import { StorageAPI } from "../../storage"
import { NotificationsAPI } from "../../notifications"

/**
 * Load user products from remote or local if not available
 */
export const load = (onlineData, allowNotifications) =>
    StorageAPI
        .getSync(null)
        .then(items => {
            delete items.lastCheck
            delete items.settings
            if ($.isEmptyObject(items)) {
                // show some text - no products marked yet
                return Promise.reject("No products tracked yet")
            } else {
                return co(function* () {
                        const products = []
                        for (let pid of Object.getOwnPropertyNames(items)) {
                            let product = {}
                            if (onlineData) {
                                product = yield EmagTrackerAPI.getProduct(pid)
                            }
                            if ($.isEmptyObject(product)) {
                                if (onlineData)
                                    console.warn("Remote fetch failed for pid=" + pid + ". Attempting to load from local.")
                                product = yield StorageAPI.getLocal(pid)
                                if (allowNotifications && $.isEmptyObject(product))
                                    NotificationsAPI.error("Could not find product " + pid)
                                else
                                    products.push(product[pid])
                            } else
                                products.push(product)
                        }
                        return products
                    })
            }
        })
{'fraction_non_alphanumeric': 0.08501118568232663, 'fraction_numerical': 0.0, 'mean_word_length': 1.037015945330296, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5193628', 'n_tokens_mistral': 748, 'n_tokens_neox': 716, 'n_words': 205}