Monday, 4 January 2010

Tales from an Admin Perspective: Code Sleuth

We had a database that we kept getting complaints about, it kept getting slower and slower to do a specific task. I tracked it down to this code.

Can you spot this issue with this code?

Sub assignAclToSubRecord( viewName, docID )
    Dim counter As Integer
    Set vwSub = db.GetView( viewName )
    Set subDoc = vwSub.GetDocumentByKey( docID )
    Do While Not ( subDoc Is Nothing )
        subDoc.Authors_Variable_SpecificTI  = currentDoc.Authors_Variable_SpecificTI
        subDoc.AuthorsVariable = currentDoc.AuthorsVariable
        Call subDoc.Save(True,True)
        Set subDoc = vwSub.GetNextDocument( subDoc )
    Loop   
End Sub

1 comment:

  1. The coder presumably intended to get a document *collection* matching some docID key and loop through just those docs. The code as is would loop through every doc in the view after the first key match, which would be an increasingly burdensome process as the number of documents increased over time.

    ReplyDelete