Archaeologist Progress / Edits


Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

-- Title or text edits on someone else's post
-- that had been idle for 6 or more months prior

with CandidateEdits as (

    -- Edits the user has made to titles/body of some other user's posts.

    select min(ph.Id) as EditId,
           ph.PostId EditPost,
           IsNull(p.ParentId, p.Id) as EditQuestion,
           ph.RevisionGUID as EditGUID,
           ph.CreationDate as EditDate
    from PostHistory as ph
        inner join Posts as p on ph.PostId = p.Id and OwnerUserId != UserId
    where UserId = ##UserId:int##
      and PostHistoryTypeId in (4,5) --Title/Body edits.
      and PostTypeId in (1, 2) -- question/answer
    group by ph.PostId, p.Id, p.ParentId, ph.RevisionGUID, ph.CreationDate

), RelatedPosts as (

    -- Posts that cannot be modified in the 6-month window

    select EditId,
           EditQuestion as RelatedPost
    from CandidateEdits
    select EditId,
           Id as RelatedPost
    from CandidateEdits, Posts
    where EditQuestion = ParentId
      and PostTypeId = 2

), Inactives as (

    -- Edits that have no activity related posts in the 6 month window.
    -- Use Left join, and have a count of 0

    select EditId,
           count(distinct RevisionGUID) as Invalidations
    from RelatedPosts Left Outer Join PostHistory on
             RelatedPost = PostId
         and CreationDate between DateAdd(mm, -6, EditDate) and EditDate
         and Id < EditId
         and RevisionGUID <> EditGUID
    group by EditId
    having count(distinct RevisionGUID) = 0

), Revisions as (

    -- Identify which revision in the system relates to the edit you made.
    -- convert to NVarchar to make concatenation simpler in result.

    select EditID,
           Convert(NVarchar(10), EditPost) as RevPost,
           Convert(NVarchar(10), count(distinct RevisionGUID)) as Revision
    from CandidateEdits inner join PostHistory
      on  PostId = EditPost
      and Id <= EditId
      and PostHistoryTypeId < 10
    group by EditId, EditPost

select Rank() over (order by EditDate) as Dig,
       EditPost as [Post Link],
       'site://revisions/' + RevPost + '/' + Revision
             + '|Revision ' + Revision as Revision
from  CandidateEdits as ce
inner join Inactives as i on ce.EditId = i.EditId
inner join Revisions as r on ce.EditId = r.EditId
order by EditDate

Enter Parameters

Switch sites:
loading Hold tight while we fetch your results