Queries the 'channels' view to get a range of sequences of a single channel as LogEntries.
(ctx context.Context, channelName string, startSeq, endSeq uint64, limit int, activeOnly bool)
| 91 | |
| 92 | // Queries the 'channels' view to get a range of sequences of a single channel as LogEntries. |
| 93 | func (c *DatabaseCollection) getChangesInChannelFromQuery(ctx context.Context, channelName string, startSeq, endSeq uint64, limit int, activeOnly bool) (LogEntries, error) { |
| 94 | if c.dataStore == nil { |
| 95 | return nil, errors.New("No data store available for channel query") |
| 96 | } |
| 97 | start := time.Now() |
| 98 | usingViews := c.useViews() |
| 99 | entries := make(LogEntries, 0) |
| 100 | activeEntryCount := 0 |
| 101 | |
| 102 | base.InfofCtx(ctx, base.KeyCache, " Querying 'channels' for %q (start=#%d, end=#%d, limit=%d)", base.UD(channelName), startSeq, endSeq, limit) |
| 103 | |
| 104 | // Loop for active-only and limit handling. |
| 105 | // The set of changes we get back from the query applies the limit, but includes both active and non-active entries. When retrieving changes w/ activeOnly=true and a limit, |
| 106 | // this means we may need multiple view calls to get a total of [limit] active entries. |
| 107 | collectionID := c.GetCollectionID() |
| 108 | for { |
| 109 | |
| 110 | // Query the view or index |
| 111 | queryResults, err := c.QueryChannels(ctx, channelName, startSeq, endSeq, limit, activeOnly) |
| 112 | if err != nil { |
| 113 | return nil, err |
| 114 | } |
| 115 | queryRowCount := 0 |
| 116 | |
| 117 | // Convert the output to LogEntries. Channel query and view result rows have different structure, so need to unmarshal independently. |
| 118 | highSeq := uint64(0) |
| 119 | for { |
| 120 | var entry *LogEntry |
| 121 | var found bool |
| 122 | if usingViews { |
| 123 | entry, found = nextChannelViewEntry(ctx, queryResults, collectionID) |
| 124 | } else { |
| 125 | entry, found = nextChannelQueryEntry(ctx, queryResults, collectionID) |
| 126 | } |
| 127 | |
| 128 | if !found { |
| 129 | break |
| 130 | } |
| 131 | |
| 132 | queryRowCount++ |
| 133 | |
| 134 | // If active-only, track the number of non-removal, non-deleted revisions we've seen in the view results |
| 135 | // for limit calculation below. |
| 136 | if activeOnly { |
| 137 | if entry.IsActive() { |
| 138 | activeEntryCount++ |
| 139 | } |
| 140 | } |
| 141 | entries = append(entries, entry) |
| 142 | highSeq = entry.Sequence |
| 143 | } |
| 144 | |
| 145 | // Close query results |
| 146 | closeErr := queryResults.Close() |
| 147 | if closeErr != nil { |
| 148 | return nil, closeErr |
| 149 | } |
| 150 |
nothing calls this directly
no test coverage detected