<commit_before>/*jslint nomen: true, vars: true, browser: true*/
/*global define*/
define(function (require) {
    'use strict';

    var server = require('./server');
    var ko = require('knockout');

    var cached = {
        books: ko.observableArray()
    };

    return {
        books: {
            data: cached.books,
            update: function () {
                return server.books.get({}, function (oldCached) {
                    if (oldCached.length) {
                        cached.books(oldCached);
                    } else {
                        server.books.get({from: 0, count: 20})
                            .then(function (newItems) {
                                if (!cached.books().length) {
                                    cached.books(newItems);
                                }
                            });
                    }
                }).then(function (newItems) {
                    cached.books(newItems);
                    return newItems;
                });
            }
        }
    };
});<commit_msg>fix empty cache handling<commit_after>/*jslint nomen: true, vars: true, browser: true*/
/*global define*/
define(function (require) {
    'use strict';

    var server = require('./server');
    var ko = require('knockout');

    var cached = {
        books: ko.observableArray()
    };

    return {
        books: {
            data: cached.books,
            update: function () {
                return server.books.get({}, function (oldCached) {
                    if (oldCached && oldCached.length) {
                        cached.books(oldCached);
                    } else {
                        server.books.get({from: 0, count: 20})
                            .then(function (newItems) {
                                if (!cached.books().length) {
                                    cached.books(newItems);
                                }
                            });
                    }
                }).then(function (newItems) {
                    cached.books(newItems);
                    return newItems;
                });
            }
        }
    };
});
{'fraction_non_alphanumeric': 0.11797235023041475, 'fraction_numerical': 0.0027649769585253456, 'mean_word_length': 1.0064695009242144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7189013', 'n_tokens_mistral': 548, 'n_tokens_neox': 507, 'n_words': 106}