collective/collective.elephantvocabulary — pull request #4 by lukasgraf (2013-10-04 09:06:09+00:00)
Title: Internal terms lists grow indefinitely when populated from registry

In [`vocabulary.py:56`](https://github.com/collective/collective.elephantvocabulary/blob/3a17957d841d2b8aba21431c33c1a9393b39c00b/collective/elephantvocabulary/vocabulary.py#L56) and [`vocabulary.py:76`](https://github.com/collective/collective.elephantvocabulary/blob/3a17957d841d2b8aba21431c33c1a9393b39c00b/collective/elephantvocabulary/vocabulary.py#L76) the internal lists `VocabularyFactory.visible_terms` and `VocabularyFactory.hidden_terms` get updated with values from the registry.

However, terms are only ever **appended** to those lists, and no check for duplicates is being done. This will cause those lists to grow indefinitely, because on ever `__call__()` the terms from the registry will be appended again. In production sites running for a couple weeks we had vocabularies with those lists having 28'000 items, most of them duplicates.

Proposed fix: Either
- iterate over `record` and only `append()` items that aren't already in the lists

or

- `extend()` the list by `record`, make it a `set` and turn it into a `list` again.

I slightly prefer the first solution because it preserves order (shouldn't matter for the implementation, but makes for writing nicer tests).