Skip to content

Commit b9143a5

Browse files
committed
Utilize new IsDirty() method for evaluating byline, dateline
Instead of manually defining `isDirty` based on a custom LINQ expression, we can now just use the new `AttributeValueCollection.IsDirty()` method introduced in the forthcoming version of the **OnTopic Library** (80fee57). Technically, because the same update of the library _also_ includes new code in the `TopicRepositoryBase` and e.g. `SqlTopicRepository` for bypassing the byline (`LastModifiedBy`) and dateline (`LastModified`) if no other attributes have been modified, we could just remove this condition entirely. As this is a cheap condition to validate, however, there remains value to retaining this condition, as it prevents the in-memory copies of the topics from being updated with the byline and dateline. That mitigates confusion of any pages displaying this information—including the **OnTopic Editor**—from being temporarily updated, even though the data won't be persisted to the repository. In addition, it avoids a rare scenario where another process subsequently modifies one or more attribute on the in-memory topic and `Save()`s it, in which case the dateline and byline would then get persisted, even though they weren't related to that operation. In practice, most subsequent updates would be done by the **OnTopic Editor**, which will always update these attributes with information about the current edit, so this remains a tail risk. Regardless, by keeping the `IsDirty()` condition in place, we prevent either of those scenarios, even if they're rare, while introducing minimal overhead.
1 parent 46c8ba3 commit b9143a5

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

OnTopic.Data.Transfer/Interchange/TopicExtensions.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,10 @@ public static void Import(this Topic topic, TopicData topicData, [NotNull]Import
207207
);
208208
}
209209

210-
/*------------------------------------------------------------------------------------------------------------------------
211-
| Determine changes
212-
\-----------------------------------------------------------------------------------------------------------------------*/
213-
214-
//Defermine if any attributes have changed
215-
var isDirty = topic.Attributes.Any(a => a.IsDirty);
216-
217210
/*------------------------------------------------------------------------------------------------------------------------
218211
| Handle special rules for LastModified(By) attribute
219212
\-----------------------------------------------------------------------------------------------------------------------*/
220-
if (isDirty) {
213+
if (topic.Attributes.IsDirty()) {
221214

222215
switch (options.LastModifiedStrategy) {
223216
case LastModifiedImportStrategy.Current:
@@ -237,14 +230,14 @@ public static void Import(this Topic topic, TopicData topicData, [NotNull]Import
237230
break;
238231
}
239232

240-
if (topic.Attributes.GetValue("LastModifiedBy", null) == null) {
241-
topic.Attributes.SetValue("LastModifiedBy", options.CurrentUser);
242-
}
243-
244233
if (topic.Attributes.GetValue("LastModified", null) == null) {
245234
topic.Attributes.SetValue("LastModified", DateTime.Now.ToString(CultureInfo.CurrentCulture));
246235
}
247236

237+
if (topic.Attributes.GetValue("LastModifiedBy", null) == null) {
238+
topic.Attributes.SetValue("LastModifiedBy", options.CurrentUser);
239+
}
240+
248241
}
249242

250243
/*------------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)