Вот мой график
g.addV('user').property('id',1).as('1').
addV('user').property('id',2).as('2').
addV('user').property('id',3).as('3').
addE('follow').from('1').to('2').
addE('follow').from('1').to('3').iterate()
Ниже приведен мой подход, когда пользователь хочет следовать за другим пользователем, предположим, что 2 хочет следовать 3
Сначала я проверяю, существует ли последующее реброот 2 до 3
if(g.V().has(id, 2).outE(follow).inV().has(id, 3).hasNext())
{
//if exists that means he already following him so i'm dropping the follow edge and adding unfollow edge to 2,3.
}
else if(g.V().has(id, 2).outE(unfollow).inV().has(id, 3).hasNext())
{
//if exists he already unfollowed him and he wants to follow him again i'm dropping the unfollow edge and adding the follow edge to 2,3.
}
else
{
// there is no edges between 2,3 so he is following him first so i'm adding follow edge 2,3.
}
, но недостаток этого подхода заключается в том, что каждый раз необходимо запрашивать 2 раза, что влияет на производительность.Можете ли вы предложить мне лучший подход?