falcor-path-utils icon indicating copy to clipboard operation
falcor-path-utils copied to clipboard

Enhancement: collapse indices to range

Open jameslaneconkling opened this issue 7 years ago • 3 comments

Collapse correctly collapses indices into a range when all indices are w/i that range. E.g.

collapse([
  ['key1', [1,2,3,4,5], 'key2']
])
// > [['key1', { from: 1, to: 5 }, 'key2']]

However, it doesn't collapse indices to a range when there are additional indices outside of that range. E.g.

collapse([
  ['key1', [1,2,3,4,5,10], 'key2']
])
// > [['key1', [1,2,3,4,5,10], 'key2']]

jameslaneconkling avatar May 28 '17 21:05 jameslaneconkling

Hey @jameslaneconkling - I believe that's currently by design. That is, we only attempt to collapse ranges when all numerical keys are contiguous. cc @jhusain @lrowe

sdesai avatar May 31 '17 04:05 sdesai

@sdesai is it a desirable enhancement? If so, I could look at a possible implementation.

The use case I'm running into often.

  • I request a range of resources, e.g. ['items', { to: 20 }, 'name']
  • One of those items is already in the cache, e.g. { items: { 4: { name: 'item 4' } } }
  • The resulting request to the router is for ['items', [0, 1, 2, 3, 5, 6, 7, ..., 20], 'name'], rather than ['items', [{ to: 3 }, { from: 5, to: 20 }], 'name']

jameslaneconkling avatar Jun 01 '17 15:06 jameslaneconkling

Hey @jameslaneconkling : The use case definitively makes sense. I'll let @jhusain or @lrowe comment on whether it's worth going after for the over-the-wire savings, and corresponding run-time trade-offs - I imagine it's something we've considered/discussed at some point and @jhusain may have that context.

sdesai avatar Jun 01 '17 17:06 sdesai