<commit_before>/*global angular, PouchDB, console */
(function SyncService() {
    'use strict';

    //
    var SyncSvc = function SyncSvc($q, $log, $window) {
        var self = this;

        // remote DB
        this.inprogress = false;
        this.refreshInterval = 30;
        this.remoteHost = 'https://vinnylinck:94kf73GS@vinnylinck.cloudant.com/todosyncpoc';
        this.opts = {
            continuous: false,
            complete: function () {
                self.refresh(self.entities.CLOUD_OPS, 0);
                self.inprogress = false;
            }
        };

        // promisses & log
        this.$q = $q;
        this.$log = $log;


        // database
        this.db = this.open();

        // callback store
        this.hooks = [];

        // entities to be 'monitored'
        this.entities = {
            TASK_LIST: 0,
            CLOUD_OPS: 1
        };

        // job for import
        $window.setInterval(function () {
            if (!self.inprogress) {
                self.inprogress = true;
                self.replicate();
            }
        }, self.refreshInterval * 1000);

    };

    SyncSvc.prototype.info = function (fn) {
        var p = this.$q.defer();
        
        this.db.info(function (err, info) {
            if (err) {
                p.reject(err);
            } else {
                p.resolve(info);
            }
        });
        
        return p.promise;
    };
    
    //
    SyncSvc.prototype.replicateTo = function () {
        this.refresh(this.entities.CLOUD_OPS, 1);

        this.db.replicate.to(this.remoteHost, this.opts);
    };

    //
    SyncSvc.prototype.replicateFrom = function () {
        this.refresh(this.entities.CLOUD_OPS, -1);

        this.db.replicate.from(this.remoteHost, this.opts);

        this.refreshAll(this.entities.TASK_LIST);
    };


    //
    SyncSvc.prototype.replicate = function () {
        try {

            this.replicateTo();
            this.replicateFrom();
            console.log('- Replication ended with success!');
        } catch (e) {
            console.log('- Failure replicating data with ', this.remoteHost, ' # ', e);
        } finally {
            console.log('- Replication ended.');
        }
    };


    //
    SyncSvc.prototype.open = function () {
        return new PouchDB('todosyncpoc');<commit_msg>Adjusted sync timing.<commit_after>/*global angular, PouchDB, console */
(function SyncService() {
    'use strict';

    //
    var SyncSvc = function SyncSvc($q, $log, $window) {
        var self = this;

        // remote DB
        this.inprogress = false;
        this.refreshInterval = 25;
        this.remoteHost = 'https://vinnylinck:94kf73GS@vinnylinck.cloudant.com/todosyncpoc';
        this.opts = {
            continuous: false,
            complete: function () {
                self.refresh(self.entities.CLOUD_OPS, 0);
                self.inprogress = false;
            }
        };

        // promisses & log
        this.$q = $q;
        this.$log = $log;


        // database
        this.db = this.open();

        // callback store
        this.hooks = [];

        // entities to be 'monitored'
        this.entities = {
            TASK_LIST: 0,
            CLOUD_OPS: 1
        };

        // job for import
        $window.setInterval(function () {
            if (!self.inprogress) {
                self.inprogress = true;
                self.replicateFrom();
            }
        }, self.refreshInterval * 1000);

    };

    SyncSvc.prototype.info = function () {
        var p = this.$q.defer();
        
        this.db.info(function (err, info) {
            if (err) {
                p.reject(err);
            } else {
                p.resolve(info);
            }
        });
        
        return p.promise;
    };
    
    //
    SyncSvc.prototype.replicateTo = function () {
        this.refresh(this.entities.CLOUD_OPS, 1);

        this.db.replicate.to(this.remoteHost, this.opts);
    };

    //
    SyncSvc.prototype.replicateFrom = function () {
        this.refresh(this.entities.CLOUD_OPS, -1);
        this.db.replicate.from(this.remoteHost, this.opts);
        this.refreshAll(this.entities.TASK_LIST);
    };

    //
    SyncSvc.prototype.open = function () {
        return new PouchDB('todosyncpoc');
{'fraction_non_alphanumeric': 0.13106007886801208, 'fraction_numerical': 0.006958942240779402, 'mean_word_length': 1.4668192219679634, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2938170', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1295, 'n_words': 223}