-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memoize vocabularies #42
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6cd0e71
cache expensive vocabulary construction
tomgross 04afde6
change cache key for taxonomy
tomgross e158e82
Fix MANIFEST.in
tomgross c3a5a24
Preparing release 1.4.4.post1
tomgross 30d7d28
Back to development: 1.4.5
tomgross f941095
Merge branch 'master' into tomgross-memoize_voc
petschki 0b6958a
make cachekey more generic
petschki 7655c8e
use super().update() for TaxonomySelectWidget
petschki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
.coverage | ||
.installed.cfg | ||
.mr.developer.cfg | ||
local.cfg | ||
bin | ||
build | ||
develop-eggs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,48 @@ | ||
from time import time | ||
from plone.memoize import ram | ||
import zope.interface | ||
import zope.component | ||
import zope.schema.interfaces | ||
|
||
from z3c.form import interfaces | ||
from z3c.form.browser.orderedselect import OrderedSelectWidget | ||
from z3c.form.widget import FieldWidget | ||
from z3c.form.widget import SequenceWidget | ||
from z3c.form.browser import widget | ||
|
||
from interfaces import ITaxonomySelectWidget | ||
|
||
ONE_DAY = 60 * 60 * 24 | ||
|
||
|
||
def _cache_one_day(fun, self): | ||
key = '{0}{1}'.format( | ||
self.field.__name__, | ||
time() // ONE_DAY | ||
) | ||
return key | ||
|
||
|
||
@zope.interface.implementer(ITaxonomySelectWidget, | ||
interfaces.IOrderedSelectWidget) | ||
class TaxonomySelectWidget(OrderedSelectWidget): | ||
zope.interface.implements(ITaxonomySelectWidget, | ||
interfaces.IOrderedSelectWidget) | ||
|
||
@ram.cache(_cache_one_day) | ||
def _get_items(self): | ||
return [ | ||
self.getItem(term, count) | ||
for count, term in enumerate(self.terms) | ||
] | ||
|
||
def update(self): | ||
"""See z3c.form.interfaces.IWidget.""" | ||
SequenceWidget.update(self) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why don't you use super(OrderedSelectWidget, self).update() here? I think widget.HTMLSelectWidget.update is not called right now. |
||
widget.addFieldClass(self) | ||
self.items = self._get_items() | ||
self.selectedItems = [ | ||
self.getItem(self.terms.getTermByToken(token), count) | ||
for count, token in enumerate(self.value)] | ||
self.notselectedItems = self.deselect() | ||
|
||
|
||
@zope.component.adapter(zope.schema.interfaces.ISequence, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add another component to the key (not sure what) so that the cache is invalidated if you change the taxonomy ttw or by import?