Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

Adding a refBuilder hangs flashlight #129

Open
tallminator opened this issue Feb 6, 2017 · 10 comments
Open

Adding a refBuilder hangs flashlight #129

tallminator opened this issue Feb 6, 2017 · 10 comments

Comments

@tallminator
Copy link

tallminator commented Feb 6, 2017

Before refBuilder:
Path:
exports.paths = [{ path: "nuggets", index: "firebase", type: "nugget", filter: function(data){ return (data.hasOwnProperty('published') && (data.published == true))||(!data.hasOwnProperty('published')); } },{ path: "tags", index: "firebase", type: "tag" } ];
Result:
image

After refBuilder:
exports.paths = [{ path: "nuggets", index: "firebase", type: "nugget", refBuilder: function(ref, path) { return ref.orderByChild('createdAt').startAt(Date.now());}, filter: function(data){ return (data.hasOwnProperty('published') && (data.published == true))||(!data.hasOwnProperty('published')); } },{ path: "tags", index: "firebase", type: "tag" } ];
Result:
image

@katowulf
Copy link
Contributor

katowulf commented Feb 6, 2017

Would need a complete, minimal repro with version info to be any help here.

@vcrepin
Copy link

vcrepin commented Feb 19, 2017

Same problem here. Using

  refBuilder: function(ref, path) {
     return ref.orderByChild('timestamp').startAt(Date.now());
  }

It does not index anything.

@sanvir10
Copy link

I've the same problem, who can help?, i added indexOn on timestamp, but this don't work, thanx.

@vcrepin
Copy link

vcrepin commented Feb 20, 2017

Put a try catch around the inner code of PathMonitor constructor to see the error in the console. The problem is there. The statement that blows is

console.log('Indexing %s/%s from DB "%s"'.grey, path.index, path.type, fbutil.pathName(this.ref));

because of fbutil.pathName().

refBuilder creates a wrong ref for a reason that I do not understand. Seems a race condition because adding some console.log here and there solved the problem for me.

@sanvir10
Copy link

sanvir10 commented Feb 20, 2017

Can you share your PathMonitor?, i put console.log

function PathMonitor(esc, path) { console.log("PathMonitor: "+JSON.stringify(path)); ...

In the config i've:
... { path : "users", index: "prototipo-flash", type : "user", refBuilder: function(ref, path) { return ref.orderBy("timestamp").startAt(Date.now()); } ...

But in the console i only see:
{"path":"users","index":"prototipo-flash","type":"user"} <- this don't contain refBuilder.

@vcrepin
Copy link

vcrepin commented Feb 20, 2017

JSON.stringify does not show functions.

Add console.log() for the ref before and after is has been replaced by refBuilder.

In my case the replacement gave a wrong ref. But after adding other console.logs, it started to give the right one. In case, console.log(ref) should be the same thing before and after the replacement.

console.log(ref) gives the firebase path to your document.

@vcrepin
Copy link

vcrepin commented Feb 20, 2017

Here is my path monitorconstructor:

function PathMonitor(esc, path) {

this.ref = fbutil.fbRef(path.path);
console.log("Created REF: "+this.ref);

if(fbutil.isFunction(path.refBuilder)) {
    this.ref = path.refBuilder(this.ref, path);
    console.log("Changed REF TO REFBUILDER: "+this.ref);
}
console.log('Indexing %s/%s from DB "%s"'.grey, path.index, path.type, fbutil.pathName(this.ref));

this.esc = esc;

this.index = path.index;
this.type = path.type;
this.filter = path.filter || function() { return true; };
this.parse = path.parser || function(data) { return parseKeys(data, path.fields, path.omit) };

this._init();
}

@vcrepin
Copy link

vcrepin commented Feb 20, 2017

By the way in fbutils you should adjust pathName like so:

exports.pathName = function(ref) {
var p = ref.parent;
return (p ? p.key+'/' : '')+ref.key;
};

@sanvir10
Copy link

sanvir10 commented Feb 20, 2017

Thanx, but the result is not indexed u.u:

`
Connecting to ElasticSearch host 89b1ead13acc93f9402a2f3107f7exxx.xx-xxxx-1.xxx.found.io:9200
Connected to ElasticSearch host 89b1ead13acc93f9402a2f3107f7exxx.xx-xxxx-1.xxx.found.io:9200
Connecting to Firebase https://xxxxxx-9cc16.firebaseio.com
Created REF: https://xxxxx-9cc16.firebaseio.com/users

`

I did the changes but not work yet, i will review later thanx.

@vcrepin
Copy link

vcrepin commented Feb 20, 2017

print your ref once replaced by refBuilder. If should be the same as before ( https://flashligth-9cc16.firebaseio.com/users)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants