• Modified "Update All Views" agent and QueryClose for Journal DB

    By Rob Breault 2 decades ago

    Modified the agent purely for speed… and skipped 'Private on first use' views that were not already set as private (since they will be copied to private usage upon first use, no one will ever use these so why rebuild them).



    Sub Initialize

    Dim views As Variant<br/>
    Dim view As NotesView<br/>
    Dim doc As NotesDocument<br/>
    Dim item As NotesItem<br/>
    Dim dt1 As NotesDateTime, dt2 As NotesDateTime  <br/>
    Dim total As Integer, count As Integer, flag_pofu As Integer, flag_p As Integer<br/>
    Dim nHours As Integer, nMinutes As Integer, nSeconds As Integer<br/>
    Dim Duration As Long<br/>
    <br/>
    Set dt1 = New NotesDateTime(Now())<br/>
    views = this_db.Views<br/>
    Total = Ubound(views)+1<br/>
    Forall v2 In views<br/>
        Set view = v2<br/>
        Set doc = this_db.GetDocumentByUNID(view.UniversalID)<br/>
        If Not (doc Is Nothing) Then<br/>
            Count = Count + 1<br/>
            Set item = doc.GetFirstItem(&quot;$Flags&quot;)<br/>
            'Flag p (lowercase P) = Private on first use<br/>
            If Instr(item.Values(0),&quot;p&quot;) Then flag_pofu = True Else flag_pofu = False<br/>
            'Flag V (uppercase V) = Private View<br/>
            If Instr(item.Values(0),&quot;V&quot;) Then flag_p = True Else flag_p = False<br/>
            If flag_pofu And Not flag_p Then<br/>
                'Skip views that are 'Private On First Use' but are not currently 'Private'...<br/>
                Print &quot;Skipping view: &quot; &amp; view.Name &amp; &quot; (&quot; &amp; Count &amp; &quot; of &quot; &amp; Total &amp; &quot;)&quot;<br/>
            Else<br/>
                Print &quot;Updating view: &quot; &amp; view.Name &amp; &quot; (&quot; &amp; Count &amp; &quot; of &quot; &amp; Total &amp; &quot;)&quot;<br/>
                Call view.Refresh()<br/>
            End If<br/>
        End If<br/>
    End Forall<br/>
    Set dt2 = New NotesDateTime(Now())<br/>
    <br/>
    Duration = dt2.TimeDifference(dt1)<br/>
    nHours = Int(Duration/ 3600)<br/>
    nMinutes = Int(Duration/ 60) - (nHours * 60)<br/>
    nSeconds = Duration - ((nHours * 3600) + (nMinutes * 60))<br/>
    <br/>
    Print &quot;Update All Views elapsed time: &quot; &amp; nHours &amp; &quot; hours, &quot; &amp; nMinutes &amp; &quot; minutes, &quot; &amp; nSeconds &amp; &quot; seconds.&quot;<br/>
    

    End Sub





    Also since the Journal is real heavy on private views, I've added a QueryClose function to the Database Script to remove them while work was in progress on the database… (this can be used on ANY database that you need to remove private views, and again its been optimized for pure speed)…



    Sub Queryclose(Source As Notesuidatabase, Continue As Variant)

    Dim views As Variant<br/>
    Dim view As NotesView<br/>
    Dim doc As NotesDocument<br/>
    Dim item As NotesItem<br/>
    Print &quot;Checking for private views...&quot;<br/>
    views = this_db.Views<br/>
    Forall v In views<br/>
        Set view = v<br/>
        Set doc = this_db.GetDocumentByUNID(view.UniversalID)<br/>
        If Not doc Is Nothing Then<br/>
            Set item = doc.GetFirstItem(&quot;$Flags&quot;)<br/>
            If Instr(item.Values(0),&quot;V&quot;) Then<br/>
                Print &quot;Removing private view: &quot; &amp; view.Name<br/>
                Call view.Remove<br/>
            End If<br/>
        End If<br/>
    End Forall<br/>
    Print &quot;&quot;<br/>
    

    End Sub



    Both use my modified CratchitCommonLibrary, so you'll need to add session and db declarations…