<commit_before>const moment = require("moment");

var fn = function(options, callback) {
    var events = {};
    options.db.pull_request.find({},{updated_at:1, html_url:1, title:1}).sort({updated_at:-1}).toArray().then(prs => {
        events.prs = prs;
        return options.db.issue.find({},{updated_at:1, html_url:1, title:1,user:1}).sort({updated_at:-1}).toArray();
    }).then(issues => {
        events.issues = issues;
        return options.db.issue_comment.find({},{updated_at:1, html_url:1, body:1, issue_url:1}).sort({updated_at:-1}).toArray();
    }).then(issue_comments => {
        events.issue_comments = issue_comments;
        var events_list = events.prs.map(o=>{
            return {
                type:"PR", 
                url:o.html_url, 
                title: o.title,
                updated_at: o.updated_at,
                ago: moment(o.updated_at).fromNow()
            }
        });
        events_list = events_list.concat(events.issues.map(o=>{
            return {
                type:"issue",
                url:o.html_url,
                title: o.html_url.split("/")[4] + ": " + o.title,
                updated_at: o.updated_at,
                ago: moment(o.updated_at).fromNow()
            }
        }));
        events_list = events_list.concat(events.issue_comments.map(o=>{
            return {
                type:"comment", 
                url:o.html_url, 
                title: o.issue_url.split("/")[5] + ": " + o.body.substr(0,20) + "...",
                updated_at: o.updated_at,
                ago: moment(o.updated_at).fromNow()
            }
        }));
        if (events_list.length > 0) {
            events_list.sort((a,b) => {
                if (a.updated_at < b.updated_at) return 1;
                if (a.updated_at > b.updated_at) return -1;
                return 0;
            })
            var result = {
                title: "Events timeline",
                columns: [{name:"Event"}, {name:"Type"}, {name: "Date"}],
                rows: events_list.map(ev => {
                    return {cells: [{text: ev.title, link: ev.url}, {text: ev.type}, {text: ev.ago}]}
                })
            }
            options.templates.table(result, callback);<commit_msg>Don't collect all the events for the timeline up front; process them as we get them, which should cut memory use a bit.<commit_after>const moment = require("moment");

var fn = function(options, callback) {
    var events_list = [];
    options.db.pull_request.find({},{updated_at:1, html_url:1, title:1}).sort({updated_at:-1}).toArray().then(prs => {
        events_list = events_list.concat(prs.map(o=>{
            return {
                type:"PR", 
                url:o.html_url, 
                title: o.title,
                updated_at: o.updated_at,
                ago: moment(o.updated_at).fromNow()
            }
        }));
        delete(prs);
        return options.db.issue.find({},{updated_at:1, html_url:1, title:1,user:1}).sort({updated_at:-1}).toArray();
    }).then(issues => {
        events_list = events_list.concat(issues.map(o=>{
            return {
                type:"issue",
                url:o.html_url,
                title: o.html_url.split("/")[4] + ": " + o.title,
                updated_at: o.updated_at,
                ago: moment(o.updated_at).fromNow()
            }
        }));
        delete(issues);
        return options.db.issue_comment.find({},{updated_at:1, html_url:1, body:1, issue_url:1}).sort({updated_at:-1}).toArray();
    }).then(issue_comments => {
        events_list = events_list.concat(issue_comments.map(o=>{
            return {
                type:"comment", 
                url:o.html_url, 
                title: o.issue_url.split("/")[5] + ": " + o.body.substr(0,20) + "...",
                updated_at: o.updated_at,
                ago: moment(o.updated_at).fromNow()
            }
        }));
        delete(issue_comments);
        if (events_list.length > 0) {
            events_list.sort((a,b) => {
                if (a.updated_at < b.updated_at) return 1;
                if (a.updated_at > b.updated_at) return -1;
                return 0;
            })
            var result = {
                title: "Events timeline",
                columns: [{name:"Event"}, {name:"Type"}, {name: "Date"}],
                rows: events_list.map(ev => {
                    return {cells: [{text: ev.title, link: ev.url}, {text: ev.type}, {text: ev.ago}]}
                })
            }
            options.templates.table(result, callback);
{'fraction_non_alphanumeric': 0.15838984904834827, 'fraction_numerical': 0.010063443447823233, 'mean_word_length': 1.6862514688601644, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 23, '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': '5551112', 'n_tokens_mistral': 1440, 'n_tokens_neox': 1376, 'n_words': 227}