如何增加Titan图形数据库“边缘标签"中的“访问次数"? [英] How to increment Number of Visit count in Titan graph database Edge Label?

查看:43
本文介绍了如何增加Titan图形数据库“边缘标签"中的“访问次数"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的顶点分别为User1和User2.当User1访问User2配置文件时,正在添加一个具有count变量的边(即Visited).

I'm having vertices as User1 and User2. When User1 visits User2 profile, am adding one edge ( i.e visited ) with count variable.

当User1再次访问User2个人资料时,如何增加计数变量.

How can i increment the count variable when User1 again visits User2 profile.

推荐答案

在使用Titan时,根据使用情况,不建议对边缘进行突变,因为它在内部会导致该边缘的删除和重新创建(注意边缘ID会发生变化).如果使用Cassandra后端,这可能会导致创建墓碑一个>,你将不得不处理自己.如果可以,请避免使边缘发生变化.实际上,边缘应被视为不变的事实"(因此不变):发生了访问事实",因此创建了访问的边缘".事实没有改变,但是新事实(新边缘)可能会使事实无效.

When using Titan, and depending on the use case, mutating an edge is not recommended as it internally leads to a deletion and re-creation of that edge (notice that the edge id will change). If using Cassandra backend, this can lead to the creation of tombstones that you will have to handle yourself. Avoid mutating edges if you can. Actually, edges should be seen as "facts" that don't change (hence the immutability): a "visit fact" happened, so a "visited edge" was created. Facts don't change, but they can be invalidated by new facts (new edges).

如果您希望用户访问量很少,则对边缘进行突变并增加count属性应该没问题,尽管您可能会失去使用图形数据库的某些好处(我会说这是一种反模式).如果您希望获得大量访问,则可能需要为每次访问添加一个新优势(我会去那条路线),对于图形数据库而言,这将是一个完美的用例.为了获得更大的访问量并更快地获取访问总数,您可能还希望通过在访问的顶点上存储一个计数器属性来跟踪访问计数(边缘计数).

If you expect the users to have few visits, mutating an edge and incrementing a count property should be fine, though you kind of lose some of the benefits of using a graph database (I'd say this is kind of an antipattern). If you expect a lot of visits, you may want to add a new edge per visit (I'd go for that route) and that would be a perfect use case for a graph database. For higher volumes and for quicker retrieval of the total number of visits, you may also want to keep track of the visit count (edge count) by storing a counter property on the visited vertex.

这篇关于如何增加Titan图形数据库“边缘标签"中的“访问次数"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆