This is a follow up question to my original question. I'm thinking of going with generating diffs and storing those diffs in the database 'History' table.

I'm using diff-match-patch library to generate what is called a 'patch'. On every save, I compare previous and new version and generate this patch. The patch could be used to generate a document at specific point in time.

My dilemma is how to store this data. Should I:

a Insert a new database record for every patch?

b. Store these patches in javascript array and store that array in history table. So there is only one db History record for document with an array of all the patches.

Concerns with:

a. Too many db records generated. Will be slow and CPU intensive to query.

b. Only one record. If record is somehow corrupted/deleted. Entire revision history is gone.

I'm looking for suggestions, concerns with either approach.

  • You should really check the history of eric sink's blog, he talks about several ways to do this and the pros and cons of each one. – stonemetal Dec 6 '12 at 19:14
  • 1
    Carefull diffing XML though, the functions that save the document could make some re-arrangements that would generate textual differences though when viewed through an XML aware differ the documents are effectively the same. – Newtopian Dec 6 '12 at 19:15
  • reverse is also true where diffing textually could result in documents that may no longer be valid to your business model. – Newtopian Dec 6 '12 at 19:16
  • @Newtopian Which functions can make re-arrangements? Is there a resource that explains it in more depth? Thank you. – dev.e.loper Dec 6 '12 at 19:38
  • 1
    Did you ever find an answer to this? – CleverPatrick Sep 4 '14 at 18:06

As you are effectively recreating some of the basic functions of an RCS in your database, you might as well look at how they store the data (whole files, diffs, etc.) and how they produce a complete document if they only store diffs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.