How insure indexing every object with Firebase FlashLight in a ElasticSearch Bonsai Free Instance

前端 未结 1 1523
时光说笑
时光说笑 2021-02-09 06:18

Thanks to the tutorial of the FlashLight https://github.com/firebase/flashlight, this is somehow easy to do fulltextsearch with Firebase.

However, if you keep the free E

1条回答
  •  伪装坚强ぢ
    2021-02-09 06:59

    If you have a bunch of data to index, the Flashlight app will ask ES to index every object on the fly, without any resource access constraint. You have to control/limit the access this share resource with a Semaphore.

    Install the Semaphore lib

    npm i --save semaphore
    

    Edit the PathMonitor.js file, and limit access to ES resource to 1

    PathMonitor.prototype = {
        _init: function () {
            this.sem = require('semaphore')(1);
            this.addMonitor = this.ref.on('child_added', this._process.bind(this, this._childAdded));
            this.changeMonitor = this.ref.on('child_changed', this._process.bind(this, this._childChanged));
            this.removeMonitor = this.ref.on('child_removed', this._process.bind(this, this._childRemoved));
        },
        ...
        _index: function (key, data, callback) {
            var that = this;
            that.sem.take(function () {
                that.esc.index({
                    index: that.index,
                    type : that.type,
                    id   : key,
                    body : data
                }, function (error, response) {
                    that.sem.leave();
                    if (callback) {
                        callback(error, response);
                    }
                }.bind(that));
            });
        },
        ...
    }
    

    This may not be required in case of paid plan.

    0 讨论(0)
提交回复
热议问题