<commit_before>﻿using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace Templar
{
    public class TemplateSource : IContentSource
    {
        private readonly string global;
        private readonly Compiler compiler;
        private readonly TemplateFinder finder;

        public TemplateSource(string global, Compiler compiler, TemplateFinder finder)
        {
            this.global = global;
            this.compiler = compiler;
            this.finder = finder;
        }

        public string GetContent(HttpContextBase httpContext)
        {
            var templates = finder.Find(httpContext);
            using (var writer = new StringWriter())
            {
                writer.WriteLine("!function() {");
                writer.WriteLine("  var templates = {0}.templates = {{}};", global);

                var results = Compile(templates);
                foreach (var result in results)
                {
                    writer.WriteLine(result);
                }

                writer.WriteLine("}();");

                return writer.ToString();
            }
        }

        private IEnumerable<string> Compile(IEnumerable<Template> templates)
        {
            return templates.AsParallel().Select(template =>
            {
                string name = template.GetName();
                string content = compiler.Compile(template.GetContent());

                return string.Format("  templates['{0}'] = {1};", name, content);
            });
        }
    }
}<commit_msg>Remove usage of parallelism when compiling templates (causing crash in Jurassic?).<commit_after>﻿using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace Templar
{
    public class TemplateSource : IContentSource
    {
        private readonly string global;
        private readonly Compiler compiler;
        private readonly TemplateFinder finder;

        public TemplateSource(string global, Compiler compiler, TemplateFinder finder)
        {
            this.global = global;
            this.compiler = compiler;
            this.finder = finder;
        }

        public string GetContent(HttpContextBase httpContext)
        {
            var templates = finder.Find(httpContext);
            using (var writer = new StringWriter())
            {
                writer.WriteLine("!function() {");
                writer.WriteLine("  var templates = {0}.templates = {{}};", global);

                var results = Compile(templates);
                foreach (var result in results)
                {
                    writer.WriteLine(result);
                }

                writer.WriteLine("}();");

                return writer.ToString();
            }
        }

        private IEnumerable<string> Compile(IEnumerable<Template> templates)
        {
            return templates.Select(template =>
            {
                string name = template.GetName();
                string content = compiler.Compile(template.GetContent());

                return string.Format("  templates['{0}'] = {1};", name, content);
            });
        }
    }
}
{'fraction_non_alphanumeric': 0.09786028949024543, 'fraction_numerical': 0.0018879798615481435, 'mean_word_length': 1.7523809523809524, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '1855828', 'n_tokens_mistral': 761, 'n_tokens_neox': 714, 'n_words': 184}