| 337 | } |
| 338 | |
| 339 | func (c *singleChannelCacheImpl) _getCachedChanges(sinceSeq uint64, limit int) (validFrom uint64, result []*LogEntry) { |
| 340 | // Find the first entry in the log to return: |
| 341 | log := c.logs |
| 342 | if len(log) == 0 { |
| 343 | validFrom = c.validFrom |
| 344 | return // Return nil if nothing is cached |
| 345 | } |
| 346 | var start int |
| 347 | for start = len(log) - 1; start >= 0 && log[start].Sequence > sinceSeq; start-- { |
| 348 | } |
| 349 | start++ |
| 350 | |
| 351 | if start > 0 { |
| 352 | validFrom = log[start-1].Sequence + 1 |
| 353 | } else { |
| 354 | validFrom = c.validFrom |
| 355 | } |
| 356 | |
| 357 | n := len(log) - start |
| 358 | |
| 359 | if limit > 0 && n > limit { |
| 360 | n = limit |
| 361 | } |
| 362 | |
| 363 | result = make([]*LogEntry, n) |
| 364 | copy(result[0:], log[start:]) |
| 365 | return |
| 366 | } |
| 367 | |
| 368 | // Top-level method to get all the changes in a channel since the sequence 'since'. |
| 369 | // If the cache doesn't go back far enough, the view will be queried. |