Skip to content

Commit

Permalink
added BTreeFolder2
Browse files Browse the repository at this point in the history
  • Loading branch information
zopyx committed Apr 25, 2005
0 parents commit bd7af2f
Show file tree
Hide file tree
Showing 15 changed files with 1,248 additions and 0 deletions.
514 changes: 514 additions & 0 deletions BTreeFolder2.py

Large diffs are not rendered by default.

Binary file added BTreeFolder2.pyc
Binary file not shown.
21 changes: 21 additions & 0 deletions CHANGES.txt
@@ -0,0 +1,21 @@
Version 1.0.1

- ConflictError was swallowed by _delObject. This could break code
expecting to do cleanups before deletion.

- Renamed hasObject() to has_key(). hasObject() conflicted with
another product.

- You can now visit objects whose names have a trailing space.

Version 1.0

- BTreeFolder2s now use an icon contributed by Chris Withers.

- Since recent ZODB releases have caused minor corruption in BTrees,
there is now a manage_cleanup method for fixing damaged BTrees
contained in BTreeFolders.

Version 0.5.1

- Fixed the CMFBTreeFolder constructor.
68 changes: 68 additions & 0 deletions CMFBTreeFolder.py
@@ -0,0 +1,68 @@
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""CMFBTreeFolder
$Id: CMFBTreeFolder.py,v 1.2 2002/10/30 14:54:18 shane Exp $
"""

import Globals
from BTreeFolder2 import BTreeFolder2Base
from Products.CMFCore.PortalFolder import PortalFolder
import Products.CMFCore.PortalFolder


_actions = Products.CMFCore.PortalFolder.factory_type_information[0]['actions']

factory_type_information = ( { 'id' : 'CMF BTree Folder',
'meta_type' : 'CMF BTree Folder',
'description' : """\
CMF folder designed to hold a lot of objects.""",
'icon' : 'folder_icon.gif',
'product' : 'BTreeFolder2',
'factory' : 'manage_addCMFBTreeFolder',
'filter_content_types' : 0,
'immediate_view' : 'folder_edit_form',
'actions' : _actions,
},
)


def manage_addCMFBTreeFolder(dispatcher, id, title='', REQUEST=None):
"""Adds a new BTreeFolder object with id *id*.
"""
id = str(id)
ob = CMFBTreeFolder(id)
ob.title = str(title)
dispatcher._setObject(id, ob)
ob = dispatcher._getOb(id)
if REQUEST is not None:
REQUEST['RESPONSE'].redirect(ob.absolute_url() + '/manage_main' )


class CMFBTreeFolder(BTreeFolder2Base, PortalFolder):
"""BTree folder for CMF sites.
"""
meta_type = 'CMF BTree Folder'

def __init__(self, id, title=''):
PortalFolder.__init__(self, id, title)
BTreeFolder2Base.__init__(self, id)

def _checkId(self, id, allow_dup=0):
PortalFolder._checkId(self, id, allow_dup)
BTreeFolder2Base._checkId(self, id, allow_dup)


Globals.InitializeClass(CMFBTreeFolder)

124 changes: 124 additions & 0 deletions README.txt
@@ -0,0 +1,124 @@

Contact
=======

Shane Hathaway
Zope Corporation
shane at zope dot com


BTreeFolder2 Product
====================

BTreeFolder2 is a Zope product that acts like a Zope folder but can
store many more items.

When you fill a Zope folder with too many items, both Zope and your
browser get overwhelmed. Zope has to load and store a large folder
object, and the browser has to render large HTML tables repeatedly.
Zope can store a lot of objects, but it has trouble storing a lot of
objects in a single standard folder.

Zope Corporation once had an extensive discussion on the subject. It
was decided that we would expand standard folders to handle large
numbers of objects gracefully. Unfortunately, Zope folders are used
and extended in so many ways today that it would be difficult to
modify standard folders in a way that would be compatible with all
Zope products.

So the BTreeFolder product was born. It stored all subobjects in a
ZODB BTree, a structure designed to allow many items without loading
them all into memory. It also rendered the contents of the folder as
a simple select list rather than a table. Most browsers have no
trouble rendering large select lists.

But there was still one issue remaining. BTreeFolders still stored
the ID of all subobjects in a single database record. If you put tens
of thousands of items in a single BTreeFolder, you would still be
loading and storing a multi-megabyte folder object. Zope can do this,
but not quickly, and not without bloating the database.

BTreeFolder2 solves this issue. It stores not only the subobjects but
also the IDs of the subobjects in a BTree. It also batches the list
of items in the UI, showing only 1000 items at a time. So if you
write your application carefully, you can use a BTreeFolder2 to store
as many items as will fit in physical storage.

There are products that depend on the internal structure of the
original BTreeFolder, however. So rather than risk breaking those
products, the product has been renamed. You can have both products
installed at the same time. If you're developing new applications,
you should use BTreeFolder2.


Installation
============

Untar BTreeFolder2 in your Products directory and restart Zope.
BTreeFolder2 will now be available in your "Add" drop-down.

Additionally, if you have CMF installed, the BTreeFolder2 product also
provides the "CMF BTree Folder" addable type.


Usage
=====

The BTreeFolder2 user interface shows a list of items rather than a
series of checkboxes. To visit an item, select it in the list and
click the "edit" button.

BTreeFolder2 objects provide Python dictionary-like methods to make them
easier to use in Python code than standard folders::

has_key(key)
keys()
values()
items()
get(key, default=None)
__len__()

keys(), values(), and items() return sequences, but not necessarily
tuples or lists. Use len(folder) to call the __len__() method. The
objects returned by values() and items() have acquisition wrappers.

BTreeFolder2 also provides a method for generating unique,
non-overlapping IDs::

generateId(prefix='item', suffix='', rand_ceiling=999999999)

The ID returned by this method is guaranteed to not clash with any
other ID in the folder. Use the returned value as the ID for new
objects. The generated IDs tend to be sequential so that objects that
are likely related in some way get loaded together.

BTreeFolder2 implements the full Folder interface, with the exception
that the superValues() method does not return any items. To implement
the method in the way the Zope codebase expects would undermine the
performance benefits gained by using BTreeFolder2.


Repairing BTree Damage
======================

Certain ZODB bugs in the past have caused minor corruption in BTrees.
Fortunately, the damage is apparently easy to repair. As of version
1.0, BTreeFolder2 provides a 'manage_cleanup' method that will check
the internal structure of existing BTreeFolder2 instances and repair
them if necessary. Many thanks to Tim Peters, who fixed the BTrees
code and provided a function for checking a BTree.

Visit a BTreeFolder2 instance through the web as a manager. Add
"manage_cleanup" to the end of the URL and request that URL. It may
take some time to load and fix the entire structure. If problems are
detected, information will be added to the event log.


Future
======

BTreeFolder2 will be maintained for Zope 2. Zope 3, however, is not
likely to require BTreeFolder, since the intention is to make Zope 3
folders gracefully expand to support many items.


51 changes: 51 additions & 0 deletions __init__.py
@@ -0,0 +1,51 @@
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
__doc__='''BTreeFolder2 Product Initialization
$Id: __init__.py,v 1.4 2003/08/21 17:03:52 shane Exp $'''
__version__='$Revision: 1.4 $'[11:-2]

import BTreeFolder2

def initialize(context):

context.registerClass(
BTreeFolder2.BTreeFolder2,
constructors=(BTreeFolder2.manage_addBTreeFolderForm,
BTreeFolder2.manage_addBTreeFolder),
icon='btreefolder2.gif',
)

#context.registerHelp()
#context.registerHelpTitle('Zope Help')

context.registerBaseClass(BTreeFolder2.BTreeFolder2)

try:
from Products.CMFCore import utils
except ImportError:
# CMF not installed
pass
else:
# CMF installed; make available a special folder type.
import CMFBTreeFolder
ADD_FOLDERS_PERMISSION = 'Add portal folders'

utils.ContentInit(
'CMF BTree Folder',
content_types=(CMFBTreeFolder.CMFBTreeFolder,),
permission=ADD_FOLDERS_PERMISSION,
extra_constructors=(CMFBTreeFolder.manage_addCMFBTreeFolder,),
fti=CMFBTreeFolder.factory_type_information
).initialize(context)

Binary file added __init__.pyc
Binary file not shown.
Binary file added btreefolder2.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bd7af2f

Please sign in to comment.