-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced new
GetTopicUpdates
stored procedure
This retrieves any updates to the database—including new or modified `Topics`, `Attributes`, `ExtendedAttributes`, `Relationships`, or `TopicReferences`—since a given date, assuming that date is within the last twenty four hours.
- Loading branch information
1 parent
bc8725a
commit 0f36947
Showing
2 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
OnTopic.Data.Sql.Database/Stored Procedures/GetTopicUpdates.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
-------------------------------------------------------------------------------------------------------------------------------- | ||
-- GET TOPIC UPDATES | ||
-------------------------------------------------------------------------------------------------------------------------------- | ||
-- Retrieves any data persisted to the database since the last query. | ||
-------------------------------------------------------------------------------------------------------------------------------- | ||
|
||
CREATE PROCEDURE [dbo].[GetTopicUpdates] | ||
@Since DATETIME | ||
AS | ||
|
||
-------------------------------------------------------------------------------------------------------------------------------- | ||
-- SELECT KEY ATTRIBUTES | ||
-------------------------------------------------------------------------------------------------------------------------------- | ||
SELECT TopicID, | ||
ContentType, | ||
ParentID, | ||
TopicKey, | ||
0 AS SortOrder | ||
FROM Topics | ||
WHERE LastModified > @Since | ||
|
||
-------------------------------------------------------------------------------------------------------------------------------- | ||
-- SELECT TOPIC ATTRIBUTES | ||
-------------------------------------------------------------------------------------------------------------------------------- | ||
;WITH TopicAttributes | ||
AS ( | ||
SELECT TopicID, | ||
AttributeKey, | ||
AttributeValue, | ||
Version, | ||
RowNumber = ROW_NUMBER() OVER ( | ||
PARTITION BY TopicID, | ||
AttributeKey | ||
ORDER BY Version DESC | ||
) | ||
FROM Attributes | ||
WHERE Version > @Since | ||
) | ||
SELECT TopicID, | ||
AttributeKey, | ||
AttributeValue, | ||
Version | ||
FROM TopicAttributes | ||
WHERE RowNumber = 1 | ||
|
||
-------------------------------------------------------------------------------------------------------------------------------- | ||
-- SELECT EXTENDED ATTRIBUTES | ||
-------------------------------------------------------------------------------------------------------------------------------- | ||
;WITH TopicExtendedAttributes | ||
AS ( | ||
SELECT TopicID, | ||
AttributesXml, | ||
Version, | ||
RowNumber = ROW_NUMBER() OVER ( | ||
PARTITION BY TopicID | ||
ORDER BY Version DESC | ||
) | ||
FROM ExtendedAttributes | ||
WHERE Version > @Since | ||
) | ||
SELECT TopicID, | ||
AttributesXml, | ||
Version | ||
FROM TopicExtendedAttributes | ||
WHERE RowNumber = 1 | ||
|
||
-------------------------------------------------------------------------------------------------------------------------------- | ||
-- SELECT RELATIONSHIPS | ||
-------------------------------------------------------------------------------------------------------------------------------- | ||
;WITH Relationships AS ( | ||
SELECT Source_TopicID, | ||
RelationshipKey, | ||
Target_TopicID, | ||
IsDeleted, | ||
Version, | ||
RowNumber = ROW_NUMBER() OVER ( | ||
PARTITION BY Source_TopicID, | ||
RelationshipKey | ||
ORDER BY Version DESC | ||
) | ||
FROM [dbo].[Relationships] | ||
WHERE Version > @Since | ||
) | ||
SELECT Relationships.Source_TopicID, | ||
Relationships.RelationshipKey, | ||
Relationships.Target_TopicID, | ||
Relationships.IsDeleted, | ||
Relationships.Version | ||
FROM Relationships | ||
WHERE RowNumber = 1 | ||
|
||
-------------------------------------------------------------------------------------------------------------------------------- | ||
-- SELECT REFERENCES | ||
-------------------------------------------------------------------------------------------------------------------------------- | ||
;WITH TopicReferences AS ( | ||
SELECT Source_TopicID, | ||
ReferenceKey, | ||
Target_TopicID, | ||
Version, | ||
RowNumber = ROW_NUMBER() OVER ( | ||
PARTITION BY Source_TopicID, | ||
ReferenceKey | ||
ORDER BY Version DESC | ||
) | ||
FROM [dbo].[TopicReferences] | ||
WHERE Version > @Since | ||
) | ||
SELECT TopicReferences.Source_TopicID, | ||
TopicReferences.ReferenceKey, | ||
TopicReferences.Target_TopicID, | ||
TopicReferences.Version | ||
FROM TopicReferences | ||
WHERE RowNumber = 1 | ||
|
||
-------------------------------------------------------------------------------------------------------------------------------- | ||
-- SELECT HISTORY | ||
-------------------------------------------------------------------------------------------------------------------------------- | ||
SELECT TopicID, | ||
Version | ||
FROM VersionHistoryIndex | ||
WHERE Version > @Since |