amark / gun

An open source cybersecurity protocol for syncing decentralized graph data.
https://gun.eco/docs
Other
18.19k stars 1.17k forks source link

map().put() #121

Open amark opened 9 years ago

amark commented 9 years ago

uggh, when I ran this code:

<html>
    <body>
        <script src="http://rawgit.com/amark/gun/master/gun.js"></script>
        <script>
            localStorage.clear();
            var gun = Gun();

            // define the snake team!
            var snakes = gun.get('team/snakes').put({team: "snakes"});

            // add members to the snake team in one go!
            snakes.path('members')
                .set({name: "alice"}).back
                .set({name: "bob"}).back

            snakes.val(function(theTeam){
                // now add the snake team as a field to each of the members.
                snakes.path('members').map().path('team').put(theTeam);
            });
        </script>
    </body>
</html>

it only added theTeam to the first item it mapped over, not both items it mapped over.

Does this happen constantly?

PsychoLlama commented 9 years ago

I've had similar issues when using .path(path).put(obj), backing out and putting again, then calling .val. It's as though like parts of the chain are breaking. Maybe something similar is happening here?

amark commented 9 years ago

perhaps. :( arrrrrrrrgggh so many bugs to fiiiix.

The power of gun's chaining API is allowing for really complex emergent behavior. However the terror of gun's chaining API is making sure that all those possible permutations work as expected and intended! Yi yi yi.

PsychoLlama commented 9 years ago

My guess is that we've got a bit of the 80-20 rule going on here, where .path seems to be at the center. If we iron out the bugs in .path, it should take care of the vast majority of our problems.

... in theory.

amark commented 9 years ago

and .map because .map allows for a context change such that this line allThePeople.map().path('friends').map().val() explodes into a N*M operation, where val gets called once for each friend, for each person.

PsychoLlama commented 9 years ago

Yipes! However, as a developer, I wouldn't expect that to be the most performant. Not the best excuse, but we should be able to back-burner it for now 😬

amark commented 9 years ago

performance is not the point here, data is the point - I might legitimately want to show a visual graph of every person's friend. I know that isn't going to be performant, but that doesn't matter it is what my app does. GUN is a good use case for this, and therefore I should expect that graph traversal query to work. And as GUN authors we need to make sure that that graph traversal query works because it uses .map and .path which need to be rock solid and work no matter how you combine them. So that shouldn't be a back-burner (unless maybe I misunderstood you. Maybe you were saying performance needs to be a back-burner? Which yeah I agree with, since it being an NM operation is unavoidable. Sure in the future we can figure out tricks that make it faster, but the point is that if it is in RAM it should be fast even as an NM).

PsychoLlama commented 9 years ago

True! I'm not saying we avoid it altogether, and we certainly shouldn't allow features to take priority over crippling performance issues. But some of our performance issues are more widespread and troublesome than others (I'm looking at you, .path). My concern is about focusing on our largest hurdles first. If that hurdle is .map, then by all means! I should've clarified further, I'm not suggesting we sweep it under the proverbial rug.

amark commented 9 years ago

ah gotcha. Yeah, what I am saying is map().path().map() or path().map().path() or any other combination isn't a "feature" it is necessarily the API itself, the contract we give developers - the only thing they can rely upon. But you are right, path's problem right now is the starting point to fix.

PsychoLlama commented 9 years ago

I agree, .map is an important method, and should be as solid as it can be. Let's talk about this some more when we meet tomorrow!

amark commented 9 years ago

Yupe :)

amark commented 7 years ago

0.5+ (current release is in 0.6 range) have MAJORLY fixed many of these issues.

However I still don't think I've tested doing a put after a map. Still would be nice, so gonna leave this open.