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

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

问题描述

让我们假设一个处理汽车的图表.
每辆 Car 都会随着时间的推移而演变,我需要跟踪这些变化.
(为了能够跟踪进化的一些不一致等......)

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...)

我考虑过实施写入时复制机制(例如 LinkedIn 似乎可以),这意味着每次 Car 的属性发生变化时,都会创建一个全新的 Car 节点.

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.

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

However, how to deal with the initial Car UUID?

我的 Car 的 UUID(即用于简化查询的索引属性)是通过库 (Apache) 自动生成的.
我想如果我为每个 Car 版本保留相同的初始 UUID,这可能会导致一些冲突:检索 UUID 为 123 的 Ferrari>" => 返回多个结果.如果 3 个版本,则返回 3 个结果.

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.

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

因此,我知道在这种情况下,检索特定版本的唯一方法是遍历图形的相关部分直到正确的部分,而不是依靠对初始 UUID 的简单查询;使用简单的 Cypher 查询,这似乎仍然非常有效和容易.

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.

我想保留生成的 UUID,因为不建议使用潜在的可猜测"REST URL(因此使用资源的 UUID).
确实,我可以有一个 UUID 作为 Car 模型与其版本之间的组合,但在我的 URL 上可见似乎还不够安全".任何恶意的人都可以通过更改 URL 轻松地设法检索旧版本.

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.

推荐答案

您应该有 2 种类型的节点(具有不同的标签)——Car 节点(如问题中的Ferrari")和 CarVersion 节点(如 Vn 节点)).只有 Car 节点应该包含 UUID.所有其他汽车数据都应该放在 CarVersion 节点中.

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.

此外,为了确保 UUID 的唯一性并加快获取特定 Car 节点的速度,您可以对 Car 节点的 UUID 属性创建唯一性约束.

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天全站免登陆