Skip to content

Commit

Permalink
support different storage types for each namespace; fixes #1777
Browse files Browse the repository at this point in the history
>>> to test or use different storage types
>>> merge changes in config/wikiconfig.py into wikiconfig.py
  • Loading branch information
RogerHaase committed Oct 30, 2024
1 parent 807bfe1 commit 3cb12ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
29 changes: 15 additions & 14 deletions src/moin/config/wikiconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ class Config(DefaultConfig):

# File Storage backends are recommended for most wikis
uri = f"stores:fs:{data_dir}/%(backend)s/%(kind)s" # use file system for storage
# uri = 'stores:sqlite:{0}/mywiki_%(backend)s_%(kind)s.db'.format(data_dir) # sqlite, 1 table per db
# uri = 'stores:sqlite:{0}/mywiki_%(backend)s.db::%(kind)s'.format(data_dir) # sqlite, 2 tables per db
# uri_sql_1 = 'stores:sqlite:{0}/mywiki_%(backend)s_%(kind)s.db'.format(data_dir) # sqlite, 1 table per db
# uri_sql_2 = 'stores:sqlite:{0}/mywiki_%(backend)s.db::%(kind)s'.format(data_dir) # sqlite, 2 tables per db
# sqlite via SQLAlchemy
# uri = 'stores:sqla:sqlite:///{0}/mywiki_%(backend)s_%(kind)s.db'.format(data_dir) # 1 table per db
# uri = 'stores:sqla:sqlite:///{0}/mywiki_%(backend)s.db:%(kind)s'.format(data_dir) # 2 tables per db
# uri_sqla_1 = 'stores:sqla:sqlite:///{0}/mywiki_%(backend)s_%(kind)s.db'.format(data_dir) # 1 table per db
# uri_sqla_2 = 'stores:sqla:sqlite:///{0}/mywiki_%(backend)s.db:%(kind)s'.format(data_dir) # 2 tables per db

namespaces = {
# maps namespace name -> backend name
Expand All @@ -166,18 +166,16 @@ class Config(DefaultConfig):
}
backends = {
# maps backend name -> storage
# the feature to use different storage types for each namespace is not implemented so use None below.
# the storage type for all backends is set in 'uri' above,
# all values in `namespace` dict must be defined as keys in `backends` dict
"default": None,
"users": None,
"userprofiles": None,
# all values in `namespaces` dict must be defined as keys in `backends` dict
"default": uri,
"users": uri,
"userprofiles": uri,
# help namespaces are optional
"help-common": None,
"help-en": None,
"help-common": uri,
"help-en": uri,
# required for foo and bar namespaces as defined above
# 'foo': None,
# 'bar': None,
# 'foo': uri,
# 'bar': uri,
}
acls = {
# maps namespace name -> acl configuration dict for that namespace
Expand Down Expand Up @@ -218,6 +216,9 @@ class Config(DefaultConfig):
hierarchic=False,
),
}

# TODO If there is a future change that requires wiki admins to merge this wikiconfig with the customized wikiconfig
# then remove the "uri" parameter in create mapping below and in storage/__init__.py.
namespace_mapping, backend_mapping, acl_mapping = create_mapping(uri, namespaces, backends, acls)
# define mapping of namespaces to unique item_roots (home pages within namespaces).
root_mapping = {"users": "UserHome"}
Expand Down
4 changes: 3 additions & 1 deletion src/moin/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ def backend_from_uri(uri):
def create_mapping(uri, namespaces, backends, acls):
namespace_mapping = namespaces.items()
acl_mapping = acls.items()
# TODO "or uri" can be removed in the future, see TODO in config/wikiconfig.py
backend_mapping = [
(backend_name, backend_from_uri(uri % dict(backend=backend_name, kind="%(kind)s"))) for backend_name in backends
(backend_name, backend_from_uri((backends[backend_name] or uri) % dict(backend=backend_name, kind="%(kind)s")))
for backend_name in backends
]
# we need the longest mountpoints first, shortest last (-> '' is very last)
namespace_mapping = sorted(namespace_mapping, key=lambda x: len(x[0]), reverse=True)
Expand Down

0 comments on commit 3cb12ad

Please sign in to comment.