<commit_before>define(function(require, exports, module) {
    "use strict";
    
    main.consumes = ["Plugin", "vfs.connect"];
    main.provides = ["vfs.cache"];
    return main;

    function main(options, imports, register) {
        var Plugin = imports.Plugin;
        var connectVfs = imports["vfs.connect"].connect;

        var async = require("async");
        var uid = require("c9/uid");
        var error = require("http-error");
        var EventEmitter = require("events").EventEmitter;
        
        /***** Initialization *****/
        
        var plugin = new Plugin("Ajax.org", main.consumes);
        var emit = plugin.getEmitter();

        var cache = {};
        var maxAge = options.maxAge || 15 * 1000;
        
        var vfsExtensions = [];
        
        /***** Methods *****/
        
        function registerExtension(handler) {
            vfsExtensions.push(handler);
        }
        
        function create(pid, user, callback) {
            var vfsid;
            do {
                vfsid = uid(16);
            } while (has(vfsid));
            
            var entry = createEntry(pid, user, vfsid);
            cache[vfsid] = entry;
            
            return connectVfs(user, pid, function(err, vfs) {
                if (err) return done(err);
                
                vfs.id = vfsid;
                vfs.uid = user.id;
                vfs.pid = pid;
                entry.vfs = vfs;
                
                async.forEach(vfsExtensions, function(factory, next) {
                    factory(vfs, next);
                }, function(err) {
                    if (err) return done(err);
                    
                    entry.connectTime = Date.now() - entry.startTime;
                    
                    entry.emit("loaded");
                    
                    cache[vfsid] = entry;
                    entry.keepalive();

                    vfs.on("destroy", function() {
                        remove(vfsid);
                    });
                    vfs.on("keepalive", function() {
                        entry.keepalive();
                        emit("keepalive", entry);
                    });
                    
                    done();
                });
            });
            
            function done(err) {
                if (err) {
                    entry.emit("fail", err);
                    remove(vfsid);
                    return callback(err);
                }
                callback(null, entry);
            }
        }
        
        function has(vfsid) {<commit_msg>monitor VFS connect time<commit_after>define(function(require, exports, module) {
    "use strict";
    
    main.consumes = [
        "Plugin",
        "vfs.connect",
        "metrics"
    ];
    main.provides = ["vfs.cache"];
    return main;

    function main(options, imports, register) {
        var Plugin = imports.Plugin;
        var connectVfs = imports["vfs.connect"].connect;
        var metrics = imports.metrics;

        var async = require("async");
        var uid = require("c9/uid");
        var error = require("http-error");
        var EventEmitter = require("events").EventEmitter;
        
        /***** Initialization *****/
        
        var plugin = new Plugin("Ajax.org", main.consumes);
        var emit = plugin.getEmitter();

        var cache = {};
        var maxAge = options.maxAge || 15 * 1000;
        
        var vfsExtensions = [];
        
        /***** Methods *****/
        
        function registerExtension(handler) {
            vfsExtensions.push(handler);
        }
        
        function create(pid, user, callback) {
            var vfsid;
            do {
                vfsid = uid(16);
            } while (has(vfsid));
            
            var entry = createEntry(pid, user, vfsid);
            cache[vfsid] = entry;
            
            return connectVfs(user, pid, function(err, vfs) {
                if (err) return done(err);
                
                vfs.id = vfsid;
                vfs.uid = user.id;
                vfs.pid = pid;
                entry.vfs = vfs;
                
                async.forEach(vfsExtensions, function(factory, next) {
                    factory(vfs, next);
                }, function(err) {
                    if (err) return done(err);
                    
                    entry.connectTime = Date.now() - entry.startTime;
                    metrics.timing("vfs.connect.time", entry.connectTime);
                    
                    entry.emit("loaded");
                    
                    cache[vfsid] = entry;
                    entry.keepalive();

                    vfs.on("destroy", function() {
                        remove(vfsid);
                    });
                    vfs.on("keepalive", function() {
                        entry.keepalive();
                        emit("keepalive", entry);
                    });
                    
                    done();
                });
            });
            
            function done(err) {
                if (err) {
                    entry.emit("fail", err);
                    remove(vfsid);
                    return callback(err);
                }
                callback(null, entry);
            }
        }
        
        function has(vfsid) {
{'fraction_non_alphanumeric': 0.11544172234595397, 'fraction_numerical': 0.0033407572383073497, 'mean_word_length': 1.053734756097561, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1857438', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1321, 'n_words': 269}