substack/npm-package-sync — pull request #1 by julianlam (2014-11-14 18:23:08+00:00)
Title: Repeated updates do not properly detect existing entries for replacement

Hi @substack. This pull request closes substack/npm-package-search#1.

I noticed that over time, the file saved to disk got larger and larger. I assume this was normal at first because the npm index is growing larger, but with a filter of `nodebb-` applied, there's no reason why a 60KB file would grow to 190KB in one week (as much as I'd love to have 3x the number of nodebb plugins, that's not the case :smile: )

Upon inspection, I noticed that when `.update()` is called, it creates a quick hash table of the existing packages' indexes, so they can be spliced out if a new entry is returned.

However, the format of this index ended up being:

``` json
[
"1": 1,
"2": 2,
...
"n": n
]
```

Based on how the `index` was being utilised, I surmised the format was supposed to be `[ "packagename": "index" ]`, and corrected the code to build the index properly.

Upon testing this fix, the file no longer increases in size, and entries are not doubled.