<commit_before>var RecipeService = function() {

    this.initialize = function() {
        // No Initialization required
        var deferred = $.Deferred();
        deferred.resolve();
        return deferred.promise();
    }

    this.findById = function(id) {
        var deferred = $.Deferred();
        var recipe = null;
        var l = recipes.length;
        for (var i=0; i < l; i++) {
            if (recipes[i].id === id) {
                recipe = recipes[i];
                break;
            }
        }
        deferred.resolve(recipe);
        return deferred.promise();
    }

    this.findByName = function(searchKey) {
        var deferred = $.Deferred();
        var results = recipes.filter(function(element) {
            var title = element.title.rendered;
            return title.toLowerCase().indexOf(searchKey.toLowerCase()) > -1;
        });
        deferred.resolve(results);
        return deferred.promise();
    }

    var recipes = null;

    $.ajaxSetup({
        beforeSend: function(xhr) {
            xhr.setRequestHeader('Access-Control-Allow-Headers', '*');
        }
    });

    $.ajax({
         type: 'GET',
         url:"http://beginveganbegun.es/wp-json/wp/v2/posts",
         crossDomain: true,
         dataType: 'json',
         success:function(data){
            recipes = data;
            debugger;
            $('#content').html(new RecipeListView(recipes).render().$el);
            console.log("Recipes loaded");
         },
         error:function(){
             console.log("Error loading recipes");
         }
    });

    this.getRecipes = function() {
      var deferred = $.Deferred();
      var results = recipes;
      deferred.resolve(results);
      return deferred.promise();
    }
}<commit_msg>Modify recipe service to only perform one call to API<commit_after>var RecipeService = function() {

    this.initialize = function() {
        // No Initialization required
        var deferred = $.Deferred();
        deferred.resolve();
        return deferred.promise();
    }

    this.findById = function(id) {
        var deferred = $.Deferred();
        var recipe = null;
        var l = recipes.length;
        for (var i=0; i < l; i++) {
            if (recipes[i].id === id) {
                recipe = recipes[i];
                break;
            }
        }
        deferred.resolve(recipe);
        return deferred.promise();
    }

    this.findByName = function(searchKey) {
        var deferred = $.Deferred();
        var results = recipes.filter(function(element) {
            var title = element.title.rendered;
            return title.toLowerCase().indexOf(searchKey.toLowerCase()) > -1;
        });
        deferred.resolve(results);
        return deferred.promise();
    }


    this.printRecipes = function() {
      if(recipes === null){
        $.ajaxSetup({
            beforeSend: function(xhr) {
                xhr.setRequestHeader('Access-Control-Allow-Headers', '*');
            }
        });

        $.ajax({
             type: 'GET',
             crossDomain: true,
             dataType: 'json',
             success:function(data){
                recipes = data;
                debugger;
                new RecipeListView(recipes).render().$el;
                console.log("Recipes loaded");
             },
             error:function(){
                 console.log("Error loading recipes");
             }
        });
      }else{
        new RecipeListView(recipes).render().$el;
      }
    }
}
{'fraction_non_alphanumeric': 0.13426453819840364, 'fraction_numerical': 0.0014253135689851768, 'mean_word_length': 1.6443104747550867, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3607410', 'n_tokens_mistral': 971, 'n_tokens_neox': 940, 'n_words': 191}