1
+ -- ------------------------------------------------------------------------------------------------------------------------------
2
+ -- GET TOPIC UPDATES
3
+ -- ------------------------------------------------------------------------------------------------------------------------------
4
+ -- Retrieves any data persisted to the database since the last query.
5
+ -- ------------------------------------------------------------------------------------------------------------------------------
6
+
7
+ CREATE PROCEDURE [dbo].[GetTopicUpdates]
8
+ @Since DATETIME
9
+ AS
10
+
11
+ -- ------------------------------------------------------------------------------------------------------------------------------
12
+ -- SELECT KEY ATTRIBUTES
13
+ -- ------------------------------------------------------------------------------------------------------------------------------
14
+ SELECT TopicID,
15
+ ContentType,
16
+ ParentID,
17
+ TopicKey,
18
+ 0 AS SortOrder
19
+ FROM Topics
20
+ WHERE LastModified > @Since
21
+
22
+ -- ------------------------------------------------------------------------------------------------------------------------------
23
+ -- SELECT TOPIC ATTRIBUTES
24
+ -- ------------------------------------------------------------------------------------------------------------------------------
25
+ ;WITH TopicAttributes
26
+ AS (
27
+ SELECT TopicID,
28
+ AttributeKey,
29
+ AttributeValue,
30
+ Version ,
31
+ RowNumber = ROW_NUMBER () OVER (
32
+ PARTITION BY TopicID,
33
+ AttributeKey
34
+ ORDER BY Version DESC
35
+ )
36
+ FROM Attributes
37
+ WHERE Version > @Since
38
+ )
39
+ SELECT TopicID,
40
+ AttributeKey,
41
+ AttributeValue,
42
+ Version
43
+ FROM TopicAttributes
44
+ WHERE RowNumber = 1
45
+
46
+ -- ------------------------------------------------------------------------------------------------------------------------------
47
+ -- SELECT EXTENDED ATTRIBUTES
48
+ -- ------------------------------------------------------------------------------------------------------------------------------
49
+ ;WITH TopicExtendedAttributes
50
+ AS (
51
+ SELECT TopicID,
52
+ AttributesXml,
53
+ Version ,
54
+ RowNumber = ROW_NUMBER () OVER (
55
+ PARTITION BY TopicID
56
+ ORDER BY Version DESC
57
+ )
58
+ FROM ExtendedAttributes
59
+ WHERE Version > @Since
60
+ )
61
+ SELECT TopicID,
62
+ AttributesXml,
63
+ Version
64
+ FROM TopicExtendedAttributes
65
+ WHERE RowNumber = 1
66
+
67
+ -- ------------------------------------------------------------------------------------------------------------------------------
68
+ -- SELECT RELATIONSHIPS
69
+ -- ------------------------------------------------------------------------------------------------------------------------------
70
+ ;WITH Relationships AS (
71
+ SELECT Source_TopicID,
72
+ RelationshipKey,
73
+ Target_TopicID,
74
+ IsDeleted,
75
+ Version ,
76
+ RowNumber = ROW_NUMBER () OVER (
77
+ PARTITION BY Source_TopicID,
78
+ RelationshipKey
79
+ ORDER BY Version DESC
80
+ )
81
+ FROM [dbo].[Relationships]
82
+ WHERE Version > @Since
83
+ )
84
+ SELECT Relationships .Source_TopicID ,
85
+ Relationships .RelationshipKey ,
86
+ Relationships .Target_TopicID ,
87
+ Relationships .IsDeleted ,
88
+ Relationships .Version
89
+ FROM Relationships
90
+ WHERE RowNumber = 1
91
+
92
+ -- ------------------------------------------------------------------------------------------------------------------------------
93
+ -- SELECT REFERENCES
94
+ -- ------------------------------------------------------------------------------------------------------------------------------
95
+ ;WITH TopicReferences AS (
96
+ SELECT Source_TopicID,
97
+ ReferenceKey,
98
+ Target_TopicID,
99
+ Version ,
100
+ RowNumber = ROW_NUMBER () OVER (
101
+ PARTITION BY Source_TopicID,
102
+ ReferenceKey
103
+ ORDER BY Version DESC
104
+ )
105
+ FROM [dbo].[TopicReferences]
106
+ WHERE Version > @Since
107
+ )
108
+ SELECT TopicReferences .Source_TopicID ,
109
+ TopicReferences .ReferenceKey ,
110
+ TopicReferences .Target_TopicID ,
111
+ TopicReferences .Version
112
+ FROM TopicReferences
113
+ WHERE RowNumber = 1
114
+
115
+ -- ------------------------------------------------------------------------------------------------------------------------------
116
+ -- SELECT HISTORY
117
+ -- ------------------------------------------------------------------------------------------------------------------------------
118
+ SELECT TopicID,
119
+ Version
120
+ FROM VersionHistoryIndex
121
+ WHERE Version > @Since
0 commit comments