Skip to content

Commit 164de05

Browse files
committed
Merge branch 'feature/ITopicRepository.Refresh' into develop
Established a new `ITopicRepository.Refresh()` interface (3d51b14), `SqlTopicRepository.Refresh()` implementation (6dbf973), as well as a `GetTopicUpdates` stored procedure (0f36947) to allow occasional cache updates without needing to reload the entire topic graph.
2 parents 4885958 + 2276083 commit 164de05

File tree

15 files changed

+636
-31
lines changed

15 files changed

+636
-31
lines changed

OnTopic.AspNetCore.Mvc.Host/SampleActivator.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class SampleActivator : IControllerActivator, IViewComponentActivator {
3434
private readonly ITypeLookupService _typeLookupService = null;
3535
private readonly ITopicMappingService _topicMappingService = null;
3636
private readonly ITopicRepository _topicRepository = null;
37+
private DateTime _cacheLastUpdated = DateTime.UtcNow;
3738

3839
/*==========================================================================================================================
3940
| HIERARCHICAL TOPIC MAPPING SERVICE
@@ -94,6 +95,15 @@ public object Create(ControllerContext context) {
9495
\-----------------------------------------------------------------------------------------------------------------------*/
9596
var type = context.ActionDescriptor.ControllerTypeInfo.AsType();
9697

98+
/*------------------------------------------------------------------------------------------------------------------------
99+
| Periodically update cache
100+
\-----------------------------------------------------------------------------------------------------------------------*/
101+
if (DateTime.UtcNow > _cacheLastUpdated.AddMinutes(1)) {
102+
var currentUpdate = DateTime.UtcNow;
103+
_topicRepository.Refresh(_topicRepository.Load(), _cacheLastUpdated);
104+
_cacheLastUpdated = currentUpdate;
105+
}
106+
97107
/*------------------------------------------------------------------------------------------------------------------------
98108
| Configure and return appropriate controller
99109
\-----------------------------------------------------------------------------------------------------------------------*/

OnTopic.Data.Caching/CachedTopicRepository.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ public CachedTopicRepository(ITopicRepository dataProvider) : base() {
131131

132132
}
133133

134+
/*==========================================================================================================================
135+
| METHOD: REFRESH
136+
\-------------------------------------------------------------------------------------------------------------------------*/
137+
/// <inheritdoc/>
138+
public override void Refresh(Topic referenceTopic, DateTime since) => _dataProvider.Refresh(referenceTopic, since);
139+
134140
/*==========================================================================================================================
135141
| METHOD: SAVE
136142
\-------------------------------------------------------------------------------------------------------------------------*/

OnTopic.Data.Sql.Database.Tests/StoredProcedures.cs

Lines changed: 159 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,20 @@ private void InitializeComponent() {
116116
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition postUpdateExtendedAttributeTopicCount;
117117
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition postUpdateExtendedAttributeCount;
118118
Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction testInitializeAction;
119+
Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction dbo_GetTopicUpdatesTest_TestAction;
120+
Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction dbo_GetTopicUpdatesTest_PretestAction;
121+
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition preGetUpdatesTopicCount;
122+
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition preGetUpdatesAttributeCount;
123+
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition preGetUpdatesRelationshipCount;
124+
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition preGetUpdatesReferenceCount;
125+
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition getUpdatesTopicCount;
126+
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition getUpdatesAttributeCount;
127+
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition getUpdatesExtendedAttributeCount;
128+
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition getUpdatesRelationshipCount;
129+
Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction dbo_GetTopicUpdatesTest_PosttestAction;
130+
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition postGetUpdatesAttributeCount;
131+
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition getUpdatesReferenceCount;
132+
Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition getUpdatesVersionHistoryCount;
119133
this.dbo_CreateTopicTestData = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestActions();
120134
this.dbo_DeleteTopicTestData = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestActions();
121135
this.dbo_GetTopicVersionTestData = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestActions();
@@ -126,6 +140,7 @@ private void InitializeComponent() {
126140
this.dbo_UpdateReferencesTestData = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestActions();
127141
this.dbo_UpdateRelationshipsTestData = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestActions();
128142
this.dbo_UpdateTopicTestData = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestActions();
143+
this.dbo_GetTopicUpdatesTestData = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestActions();
129144
dbo_CreateTopicTest_TestAction = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction();
130145
createTopicTotal = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
131146
dbo_DeleteTopicTest_TestAction = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction();
@@ -210,6 +225,20 @@ private void InitializeComponent() {
210225
postUpdateExtendedAttributeTopicCount = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
211226
postUpdateExtendedAttributeCount = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
212227
testInitializeAction = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction();
228+
dbo_GetTopicUpdatesTest_TestAction = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction();
229+
dbo_GetTopicUpdatesTest_PretestAction = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction();
230+
preGetUpdatesTopicCount = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
231+
preGetUpdatesAttributeCount = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
232+
preGetUpdatesRelationshipCount = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
233+
preGetUpdatesReferenceCount = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
234+
getUpdatesTopicCount = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
235+
getUpdatesAttributeCount = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
236+
getUpdatesExtendedAttributeCount = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
237+
getUpdatesRelationshipCount = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
238+
dbo_GetTopicUpdatesTest_PosttestAction = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestAction();
239+
postGetUpdatesAttributeCount = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
240+
getUpdatesReferenceCount = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
241+
getUpdatesVersionHistoryCount = new Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions.RowCountCondition();
213242
//
214243
// dbo_CreateTopicTest_TestAction
215244
//
@@ -790,6 +819,42 @@ private void InitializeComponent() {
790819
postUpdateExtendedAttributeCount.ResultSet = 1;
791820
postUpdateExtendedAttributeCount.RowCount = 0;
792821
//
822+
// testInitializeAction
823+
//
824+
resources.ApplyResources(testInitializeAction, "testInitializeAction");
825+
//
826+
// dbo_GetTopicUpdatesTest_TestAction
827+
//
828+
dbo_GetTopicUpdatesTest_TestAction.Conditions.Add(getUpdatesTopicCount);
829+
dbo_GetTopicUpdatesTest_TestAction.Conditions.Add(getUpdatesAttributeCount);
830+
dbo_GetTopicUpdatesTest_TestAction.Conditions.Add(getUpdatesExtendedAttributeCount);
831+
dbo_GetTopicUpdatesTest_TestAction.Conditions.Add(getUpdatesRelationshipCount);
832+
dbo_GetTopicUpdatesTest_TestAction.Conditions.Add(getUpdatesReferenceCount);
833+
dbo_GetTopicUpdatesTest_TestAction.Conditions.Add(getUpdatesVersionHistoryCount);
834+
resources.ApplyResources(dbo_GetTopicUpdatesTest_TestAction, "dbo_GetTopicUpdatesTest_TestAction");
835+
//
836+
// dbo_GetTopicUpdatesTest_PretestAction
837+
//
838+
dbo_GetTopicUpdatesTest_PretestAction.Conditions.Add(preGetUpdatesTopicCount);
839+
dbo_GetTopicUpdatesTest_PretestAction.Conditions.Add(preGetUpdatesAttributeCount);
840+
dbo_GetTopicUpdatesTest_PretestAction.Conditions.Add(preGetUpdatesRelationshipCount);
841+
dbo_GetTopicUpdatesTest_PretestAction.Conditions.Add(preGetUpdatesReferenceCount);
842+
resources.ApplyResources(dbo_GetTopicUpdatesTest_PretestAction, "dbo_GetTopicUpdatesTest_PretestAction");
843+
//
844+
// preGetUpdatesTopicCount
845+
//
846+
preGetUpdatesTopicCount.Enabled = true;
847+
preGetUpdatesTopicCount.Name = "preGetUpdatesTopicCount";
848+
preGetUpdatesTopicCount.ResultSet = 1;
849+
preGetUpdatesTopicCount.RowCount = 3;
850+
//
851+
// preGetUpdatesAttributeCount
852+
//
853+
preGetUpdatesAttributeCount.Enabled = true;
854+
preGetUpdatesAttributeCount.Name = "preGetUpdatesAttributeCount";
855+
preGetUpdatesAttributeCount.ResultSet = 2;
856+
preGetUpdatesAttributeCount.RowCount = 8;
857+
//
793858
// dbo_CreateTopicTestData
794859
//
795860
this.dbo_CreateTopicTestData.PosttestAction = dbo_CreateTopicTest_PosttestAction;
@@ -850,9 +915,79 @@ private void InitializeComponent() {
850915
this.dbo_UpdateTopicTestData.PretestAction = dbo_UpdateTopicTest_PretestAction;
851916
this.dbo_UpdateTopicTestData.TestAction = dbo_UpdateTopicTest_TestAction;
852917
//
853-
// testInitializeAction
918+
// dbo_GetTopicUpdatesTestData
854919
//
855-
resources.ApplyResources(testInitializeAction, "testInitializeAction");
920+
this.dbo_GetTopicUpdatesTestData.PosttestAction = dbo_GetTopicUpdatesTest_PosttestAction;
921+
this.dbo_GetTopicUpdatesTestData.PretestAction = dbo_GetTopicUpdatesTest_PretestAction;
922+
this.dbo_GetTopicUpdatesTestData.TestAction = dbo_GetTopicUpdatesTest_TestAction;
923+
//
924+
// preGetUpdatesRelationshipCount
925+
//
926+
preGetUpdatesRelationshipCount.Enabled = true;
927+
preGetUpdatesRelationshipCount.Name = "preGetUpdatesRelationshipCount";
928+
preGetUpdatesRelationshipCount.ResultSet = 3;
929+
preGetUpdatesRelationshipCount.RowCount = 2;
930+
//
931+
// preGetUpdatesReferenceCount
932+
//
933+
preGetUpdatesReferenceCount.Enabled = true;
934+
preGetUpdatesReferenceCount.Name = "preGetUpdatesReferenceCount";
935+
preGetUpdatesReferenceCount.ResultSet = 3;
936+
preGetUpdatesReferenceCount.RowCount = 2;
937+
//
938+
// getUpdatesTopicCount
939+
//
940+
getUpdatesTopicCount.Enabled = true;
941+
getUpdatesTopicCount.Name = "getUpdatesTopicCount";
942+
getUpdatesTopicCount.ResultSet = 5;
943+
getUpdatesTopicCount.RowCount = 1;
944+
//
945+
// getUpdatesAttributeCount
946+
//
947+
getUpdatesAttributeCount.Enabled = true;
948+
getUpdatesAttributeCount.Name = "getUpdatesAttributeCount";
949+
getUpdatesAttributeCount.ResultSet = 2;
950+
getUpdatesAttributeCount.RowCount = 4;
951+
//
952+
// getUpdatesExtendedAttributeCount
953+
//
954+
getUpdatesExtendedAttributeCount.Enabled = true;
955+
getUpdatesExtendedAttributeCount.Name = "getUpdatesExtendedAttributeCount";
956+
getUpdatesExtendedAttributeCount.ResultSet = 3;
957+
getUpdatesExtendedAttributeCount.RowCount = 2;
958+
//
959+
// getUpdatesRelationshipCount
960+
//
961+
getUpdatesRelationshipCount.Enabled = true;
962+
getUpdatesRelationshipCount.Name = "getUpdatesRelationshipCount";
963+
getUpdatesRelationshipCount.ResultSet = 4;
964+
getUpdatesRelationshipCount.RowCount = 1;
965+
//
966+
// dbo_GetTopicUpdatesTest_PosttestAction
967+
//
968+
dbo_GetTopicUpdatesTest_PosttestAction.Conditions.Add(postGetUpdatesAttributeCount);
969+
resources.ApplyResources(dbo_GetTopicUpdatesTest_PosttestAction, "dbo_GetTopicUpdatesTest_PosttestAction");
970+
//
971+
// postGetUpdatesAttributeCount
972+
//
973+
postGetUpdatesAttributeCount.Enabled = true;
974+
postGetUpdatesAttributeCount.Name = "postGetUpdatesAttributeCount";
975+
postGetUpdatesAttributeCount.ResultSet = 1;
976+
postGetUpdatesAttributeCount.RowCount = 0;
977+
//
978+
// getUpdatesReferenceCount
979+
//
980+
getUpdatesReferenceCount.Enabled = true;
981+
getUpdatesReferenceCount.Name = "getUpdatesReferenceCount";
982+
getUpdatesReferenceCount.ResultSet = 5;
983+
getUpdatesReferenceCount.RowCount = 1;
984+
//
985+
// getUpdatesVersionHistoryCount
986+
//
987+
getUpdatesVersionHistoryCount.Enabled = true;
988+
getUpdatesVersionHistoryCount.Name = "getUpdatesVersionHistoryCount";
989+
getUpdatesVersionHistoryCount.ResultSet = 6;
990+
getUpdatesVersionHistoryCount.RowCount = 2;
856991
//
857992
// StoredProcedures
858993
//
@@ -1085,6 +1220,27 @@ public void dbo_UpdateTopicTest() {
10851220
SqlExecutionResult[] posttestResults = TestService.Execute(this.PrivilegedContext, this.PrivilegedContext, testActions.PosttestAction);
10861221
}
10871222
}
1223+
[TestMethod()]
1224+
public void dbo_GetTopicUpdatesTest() {
1225+
SqlDatabaseTestActions testActions = this.dbo_GetTopicUpdatesTestData;
1226+
// Execute the pre-test script
1227+
//
1228+
System.Diagnostics.Trace.WriteLineIf((testActions.PretestAction != null), "Executing pre-test script...");
1229+
SqlExecutionResult[] pretestResults = TestService.Execute(this.PrivilegedContext, this.PrivilegedContext, testActions.PretestAction);
1230+
try {
1231+
// Execute the test script
1232+
//
1233+
System.Diagnostics.Trace.WriteLineIf((testActions.TestAction != null), "Executing test script...");
1234+
SqlExecutionResult[] testResults = TestService.Execute(this.ExecutionContext, this.PrivilegedContext, testActions.TestAction);
1235+
}
1236+
finally {
1237+
// Execute the post-test script
1238+
//
1239+
System.Diagnostics.Trace.WriteLineIf((testActions.PosttestAction != null), "Executing post-test script...");
1240+
SqlExecutionResult[] posttestResults = TestService.Execute(this.PrivilegedContext, this.PrivilegedContext, testActions.PosttestAction);
1241+
}
1242+
}
1243+
10881244
private SqlDatabaseTestActions dbo_CreateTopicTestData;
10891245
private SqlDatabaseTestActions dbo_DeleteTopicTestData;
10901246
private SqlDatabaseTestActions dbo_GetTopicVersionTestData;
@@ -1095,5 +1251,6 @@ public void dbo_UpdateTopicTest() {
10951251
private SqlDatabaseTestActions dbo_UpdateReferencesTestData;
10961252
private SqlDatabaseTestActions dbo_UpdateRelationshipsTestData;
10971253
private SqlDatabaseTestActions dbo_UpdateTopicTestData;
1254+
private SqlDatabaseTestActions dbo_GetTopicUpdatesTestData;
10981255
}
10991256
}

0 commit comments

Comments
 (0)