使用 C# GetHashCode() 比较数据图
我有一个数据图表,我使用多个 REST 调用从 OAuth 源中提取数据并将其关联存储在数据库中。该数据结构最终包含大约 5-10 个具有多个一对多关系的表。我想定期重新检索该信息,以查看我的数据库是否需要更新。
由于我将为许多用户执行此操作,并且他们的数据可能不会经常更改,因此我的目标是最大限度地减少数据库上不必要的负载。我的策略是从 OAuth 提供程序查询数据,然后对结果进行哈希处理,并将其与我为同一数据集生成的最后一个哈希值进行比较。如果哈希值不匹配,那么我只需在数据库中启动一个事务,清除该用户的所有数据,重新写入数据,然后关闭事务。这节省了我从数据库读取数据并进行所有比较工作以查看更改的内容、添加了哪些行、删除了哪些更改等的时间。
所以我的问题是:如果我将所有数据作为一个大字符串在内存中粘合在一起并使用 C# GetHasCode(),这是检查我的数据是否已更改的相当可靠的机制吗?或者,有没有更好的技术来给这只猫剥皮?
谢谢
I have a graph of data that I'm pulling from an OAuth source using several REST calls and storing relationally in a database. The data structure ends up having about 5-10 tables with several one-to-many relationships. I'd like to periodically go a re-retrieve that information to see if updates are necessary in my database.
Since I'm going to be doing this for many users and their data will likely not change very often, my goal is to minimize the load on my database unnecessarily. My strategy is to query the data from my OAuth provider but then hash the results and compare it to the last hash that I generated for the same dataset. If the hashes don't match, then I would simply start a transaction in the database, blow away all the data for that user, re-write the data, and close the transaction. This saves me the time of reading in the data from the database and doing all the compare work to see what's changed, what rows were added, deleted changed etc.
So my question: if I glue all my data together in memory as a big string and use C# GetHasCode(), is that fairly reliable mechanism to check if my data has changed? Or, are there any better techniques to skinning this cat?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是一个相当可靠的检测变化的机制。我不知道 GetHashCode() 方法中发生冲突的概率,但我认为它是安全的。
更好的方法:数据不能有每次更改时设置的版本标记或时间戳吗?
Yes, that's a fairly reliable mechanism to detect changes. I do not know about the probabilty of collisions in the GetHashCode() Method, but I'd assume it to be safe.
Better methods: Can't the data have a version-stamp or timestamp that is set everytime something changes?