Skip to content

Commit cdfe2c5

Browse files
committed
Skip indexed attributes if only the dateline, byline have changed
In the previous commit (d3b49ff), we introduced an overload to `AttributeValueCollection` which can determine if any attribute values have changed (`IsDirty`), while optionally excluding the dateline (`LastModified`) and byline (`LastModifiedBy`). In this commit, we implement this new `IsdDirty()` method as a condition around the indexed attributes in `Save()`. This ensures that the indexed attributes aren't updated—thus bypassing the `LastModified` and `LastModifiedBy` updates—if no attributes have been updated outside of the auto-generated dateline and byline. This is useful for preventing extraneous and otherwise unnecessary attributes and versions from being added to the database. This will also allow us to remove similar code from the **OnTopic Data Exchange** library—which deals with the same issue when importing JSON data—thus centralizing that implementation. Technically, these extraneous fields don't hurt anything. But they tend to clutter up the database, making it a bit cumbersome to sort through attribute versions. They can also introduce a lot of versions which, if rolled back to, don't actually change any attribute values outside of the dateline and byline. As such, removing these helps reduce noise which, in most cases, isn't adding any value. (Usually this happens because an editor saves a topic after changing nested topics—which is unnecessary, but difficult to communicate via the editor, so we've accepted it as an otherwise harmless action some editors will take.) This will result in skipping a dateline and byline if an editor only modifies relationships. In the future, we might consider making a more sophisticated version of this which accounts for relationships, but for now that's an outside use case that adds a lot of complexity and isn't a priority. This supports Remove byline and dateline if no other attributes are updated (#20).
1 parent d3b49ff commit cdfe2c5

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

OnTopic.Data.Sql/SqlTopicRepository.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,22 @@ public override int Save([NotNull]Topic topic, bool isRecursive = false, bool is
289289
/*------------------------------------------------------------------------------------------------------------------------
290290
| Add indexed attributes that are dirty
291291
\-----------------------------------------------------------------------------------------------------------------------*/
292-
foreach (var attributeValue in GetAttributes(topic, false, true)) {
292+
//Exclude indexed attributes if the only dirty attributes are `LastModified` and/or `LastModifiedBy`, as these are
293+
//automatically generated and don't represent genuine changes to the topic.
294+
if (topic.Attributes.IsDirty(true)) {
293295

294-
var record = attributes.NewRow();
295-
record["AttributeKey"] = attributeValue.Key;
296-
record["AttributeValue"]= attributeValue.Value;
297-
attributeValue.IsDirty = false;
296+
var indexedAttributes = GetAttributes(topic, false, true);
298297

299-
attributes.Rows.Add(record);
298+
foreach (var attributeValue in indexedAttributes) {
299+
300+
var record = attributes.NewRow();
301+
record["AttributeKey"] = attributeValue.Key;
302+
record["AttributeValue"]= attributeValue.Value;
303+
attributeValue.IsDirty = false;
304+
305+
attributes.Rows.Add(record);
306+
307+
}
300308

301309
}
302310

0 commit comments

Comments
 (0)