Skip to content

Commit

Permalink
addresses #4, allows third party software to define which indexes are…
Browse files Browse the repository at this point in the history
… used
  • Loading branch information
jensens committed Feb 8, 2019
1 parent 2d5ead3 commit ce411f5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
5 changes: 3 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CHANGES
*******

0.7.2 (unreleased)
0.8.0 (unreleased)
==================

Breaking changes:
Expand All @@ -10,7 +10,8 @@ Breaking changes:

New features:

- *add item here*
- addresses #4, allows third party software to define which indexes are used.
[jensens]

Bug fixes:

Expand Down
50 changes: 39 additions & 11 deletions src/z3c/relationfield/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,35 @@

import BTrees

DEFAULT_INDEXES = [
{
'name': 'from_id',
},
{
'name': 'to_id',
},
{
'name': 'from_attribute',
'kwargs': {
'btree': BTrees.family32.OI,
},
},
{
'name': 'from_interfaces_flattened',
'kwargs': {
'btree': BTrees.family32.OI,
'multiple': True,
},
},
{
'name': 'to_interfaces_flattened',
'kwargs': {
'btree': BTrees.family32.OI,
'multiple': True,
},
},
]


def dump(obj, catalog, cache):
intids = cache.get('intids')
Expand All @@ -22,15 +51,14 @@ def load(token, catalog, cache):

class RelationCatalog(Catalog):

def __init__(self):
def __init__(self, indexes=DEFAULT_INDEXES):
"""initialize the catalog with indexes.with
Uses defaults if not special configuration was passed.was
"""
Catalog.__init__(self, dump, load)
self.addValueIndex(IRelationValue['from_id'])
self.addValueIndex(IRelationValue['to_id'])
self.addValueIndex(IRelationValue['from_attribute'],
btree=BTrees.family32.OI)
self.addValueIndex(IRelationValue['from_interfaces_flattened'],
multiple=True,
btree=BTrees.family32.OI)
self.addValueIndex(IRelationValue['to_interfaces_flattened'],
multiple=True,
btree=BTrees.family32.OI)
for index in indexes:
self.addValueIndex(
IRelationValue[index['name']],
**index.get('kwargs', {})
)

0 comments on commit ce411f5

Please sign in to comment.