Neo4j /保存节点变更历史的策略 [英] Neo4j / Strategy to keep history of node changes

查看:469
本文介绍了Neo4j /保存节点变更历史的策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们假设一个处理汽车的图表。

每个 Car 可以随着时间发展,我需要跟踪这些变化。 >
(为了能够跟踪进化的一些不一致等等)



我考虑实现一个写时复制机制(如 LinkedIn 似乎是这样),意思是创建一个完整的新的 Car 节点,每次 Car 的属性之一更改。



我最终会得到如下图表:

 (法拉利) -  [:CURRENT]  - >(V3 ) -  [:PREVIOUS]  - >(V2) -  [:PREVIOUS]  - >(V1)

我有兴趣检索最新版本,所以听起来不错。



但是,如何处理初始的 Car UUID?



我的 Car 的UUID(即缓解查询的索引属性)是通过库自动生成的(Apache)。

我想像如果我为每个 Car 版本保留相同的初始UUID,这可能会导致一些冲突:检索法拉利其UUID为123 =>返回多个结果.. 3个结果如果3个版本。



为每个版本生成新品牌UUID是否安全有效?



<因此,我知道,在这种情况下,检索特定版本的唯一方法是遍历图的有关部分,直到正确的一个,而不是依赖于初始UUID上的简单查询;通过简单的Cypher查询,这仍然似乎非常高效和简单。



我想保留生成的UUID,因为有潜在的可猜测的REST URL(使用资源的UUID)不可取。

的确,我可以有一个UUID是 Car 模型及其版本之间的组合,但是似乎不够安全对我的URLS的可见性。任何恶意的人都可以轻松地通过更改URL来管理旧版本。

解决方案

您应该有两种类型的节点(不同的标签) - 汽车节点(如您的问题中的Ferrari和CarVersion节点(如Vn节点)。只有Car节点应该包含UUID。所有其他汽车数据应该在CarVersion节点中。



另外,为了确保UUID是独一无二的,并且使得更快地获得特定的Car节点,您可以创建唯一性对您的Car节点的UUID属性的约束。


Let's assume a graph dealing with cars.
Each Car can evolve over time, and I need to keep track of those changes.
(in order to be able to track some inconsistency of evolution etc...)

I thought about implementing a copy-on-write mechanism (like LinkedIn seems to do), meaning creating a complete new Car node each time one of the Car's properties changes.

I would end up with a graph like this:

(Ferrari)-[:CURRENT]->(V3)-[:PREVIOUS]->(V2)-[:PREVIOUS]->(V1)

I'm specifically interested in retrieving the most current version, so it would sound good.

However, how to deal with the initial Car UUID?

My Car's UUID (that is an indexed property to ease queries) is auto-generated through a library (Apache).
I imagine that if I keep the same initial UUID for each Car version, this might lead to some conflict: "Retrieve the Ferrari whose UUID is 123" => returning more than one result.. 3 results if 3 versions.

Is it safe and efficient to generate a new brand UUID for each version?

Thus, I'm aware than in this case, the only way to retrieve a particular version would then be to traverse the concerned portion of graph until the correct one, and not counting on a simple query on the initial UUID; that still seems very efficient and easy with a simple Cypher query.

I want to keep a generated UUID since having potential "guessable" REST URL (using resource's UUID so) is not advisable.
Indeed, I could have an UUID being the combination between the Car model and its version, but it seems not enough "safe" with a visibility on my URLS. Any malicious person could easily manage to retrieve an older version just by changing the URL.

解决方案

You should have 2 types of nodes (with different labels) -- Car nodes (like "Ferrari" in your question) and CarVersion nodes (like the Vn nodes). Only the Car nodes should contain the UUID. All the other car data should go in the CarVersion nodes.

Also, to ensure the UUIDs are unique and to make getting a specific Car node faster, you can create a uniqueness constraint on the UUID property of your Car nodes.

这篇关于Neo4j /保存节点变更历史的策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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