This document describes how the backend services should use to view to detect changes in records.
Given that we want to work on Views of data, we want to be able to monitor when an object View has changed. We say that an object View has changed if any of the objects in the View have changed. We use the term Record to denote the set of objects in a view.
States in Fedora get special treatment for Records. A Record is considered Active if the entry object in the record is Active. A Record is considered Deleted if the entry object is Deleted. And of course, a Record is Inactive if the entry object is inactive. A Record cannot formally be in several states at once, but it is more useful to consider the three states as three branches of the Record. Even if the Record is inactive, you can get the latest active version of the Record.
We want to be able to return all Records in a given Collection for a given State that have been modified after a given Time. To do this, we maintain a database of Views that is updated on all changes of an object.
To find changed records we will ask for a set of entry objects with the following criteria
We will then get a list of records, sorted by the timestamps with these fields
. For each entry pid, we can construct the Record by the method CalculateView, as it looked at the given timestamp.
Whenever one of the objects in a Record is changed, the whole Record counts as updated. As such, any services that subscribe to the Repository in any way need to be notified. If there is a search index for the Records, and one is updated, its state in the index must be recomputed.
The problem arrives when trying to do this. The View system is designed to ease the computing of a Record when knowing the Entry object. The reverse is finding the Records, ie. the Entry objects, that have this data object in their View. Rather than encoding this information in the model, we chose to keep an external record of all the views.
The external record will be a database. It will have two tables.
The first table, RECORDS, will have these columns
EntryPid, viewAngle and Collection will form a key.
The second table, OBJECTS, will have these columns
The two tables will have a many-to-many relation, linking objectPid to (EntryPid,ViewAngle,Collection)
Basically, we need three kinds of operations to handle updates:
There are a fixed number of operations that can be done on objects in doms.
For each of these, this is what should be done on the index as a result
Object Created: The Object was created in DOMS
modifyState(Inactive) reconnectObjects() updateTimestamps()
Object Deleted: The Object was purged from DOMS
modifyState(Deleted) updateTimestamps() if content model for all objects of this class reconnectObjects() updateTimestamp()
Object State Changed: The Object changed state in DOMS
Datastream Changed: The Object datastreams changed. Handled differently depending on whether this is the relations datastream
if RELS-EXT reconnectObjects(this) fi updateTimestamp(this) if VIEW and Content Model for all objects of this class reconnectObjects(object) updateTimestamp(object) fi
Object Relations Changed: The Object changed in a fashion that DOES require the view to be recomputed.
reconnectObjects(this) updateTimestamp(this) if this is a content model for all objects of this class reconnectObjects(object of this class) updateTimestamp(object of this class)
Each of these operations will be elaborated below
Param new state (one of Active, Inactive or Deleted)
if new state is not Deleted
If the new state is Deleted
select Records from OBJECTS where Deleted Timestamp <= Inactive Timestamp
An object's relations changed or an object was deleted. This could change which objects are in which entry's views.
Get the view Information about this object (Which viewAngles is this object entry for)
get the Collection information about this object (which collections is it in)
Create Records in RECORDS corresponding to all these view angles and collections (if they do not exist already) with the Inactive Timestamp set
For each Record in RECORDS with this entry pid and not in this set of view angles or not in this set of collections
Set Deleted Timestamp
unset Inactive and Active Timestamp
for each Record this object is part of (query OBJECTS with objectPid = this pull)
recalculate view of entryPid/viewAngle
There are a number of cases, which are better to discuss now
Purge of content models are meaningful. Mark as deleted does not matter, as no content model states matter
A content model table, to quickly check if you are a content model and what you are entry for could speed things up a lot