Skip to content

Commit

Permalink
Merge pull request #1651 from UlrichB22/load_add_idx
Browse files Browse the repository at this point in the history
CLI: add index build to load command
  • Loading branch information
RogerHaase authored Mar 23, 2024
2 parents 1d0fd0a + e0eaefb commit b235340
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 20 deletions.
4 changes: 1 addition & 3 deletions docs/admin/backup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,4 @@ To load the backup file into your empty wiki, run::

moin load --file backup.moin

Then build an index of the loaded data::

moin index-build
The index is removed and automatically recreated by the load command.
1 change: 1 addition & 0 deletions docs/admin/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ If your wiki has data and is shut down
If index needs a rebuild for some reason, e.g. index lost, index damaged,
incompatible upgrade, etc., use::

moin index-destroy
moin index-create
moin index-build # can take a while...

Expand Down
4 changes: 2 additions & 2 deletions src/moin/cli/_tests/test_serialization.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright: 2023 MoinMoin project
# Copyright: 2024 MoinMoin:UlrichB
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
Expand Down Expand Up @@ -28,8 +29,7 @@ def load(restore_dir, backup_name, artifact_dir, args=None):
try:
for command in (['moin', 'create-instance'],
['moin', 'index-create'],
['moin', 'load', '-f', getBackupPath(backup_name)] + (args if args else []),
['moin', 'index-build']):
['moin', 'load', '-f', getBackupPath(backup_name)] + (args if args else []),):
p = run(command)
assert_p_succcess(p)
finally:
Expand Down
17 changes: 17 additions & 0 deletions src/moin/cli/_util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright: 2023 MoinMoin project
# Copyright: 2024 MoinMoin:UlrichB
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
Expand Down Expand Up @@ -32,3 +33,19 @@ def get_backends(backends: Optional[str], all_backends: bool) -> Set[Backend]:
else:
logging.warning('no backends specified')
return set()


def drop_and_recreate_index(indexer):
"""Drop index and recreate, rebuild and optimize
:param indexer: IndexingMiddleware object
"""
indexer.close()
indexer.destroy()
logging.debug("Create index")
indexer.create()
logging.debug("Rebuild index")
indexer.rebuild()
logging.debug("Optimize index")
indexer.optimize_index()
indexer.open()
logging.info("Rebuild index finished")
7 changes: 5 additions & 2 deletions src/moin/cli/maint/serialization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright: 2011 MoinMoin:ThomasWaldmann
# Copyright: 2023 MoinMoin project
# Copyright: 2024 MoinMoin:UlrichB
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
Expand All @@ -14,7 +15,7 @@

from moin.storage.middleware.serialization import serialize, deserialize
from moin.app import create_app
from moin.cli._util import get_backends
from moin.cli._util import get_backends, drop_and_recreate_index

from moin import log
logging = log.getLogger(__name__)
Expand Down Expand Up @@ -82,4 +83,6 @@ def Deserialize(file=None, new_ns=None, old_ns=None, kill_ns=None):
logging.info("Load backup started")
with open_file(file, "rb") as f:
deserialize(f, app.storage.backend, new_ns=new_ns, old_ns=old_ns, kill_ns=kill_ns)
logging.info("Load Backup finished. You need to run index-build now.")
logging.info("Rebuilding the index ...")
drop_and_recreate_index(app.storage)
logging.info("Load Backup finished.")
11 changes: 2 additions & 9 deletions src/moin/cli/migration/moin19/import19.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from .macros import PageList # noqa

from moin.app import create_app
from moin.cli._util import drop_and_recreate_index
from moin.constants.keys import * # noqa
from moin.constants.contenttypes import CONTENTTYPE_USER, CHARSET19, CONTENTTYPE_MARKUP_OUT
from moin.constants.itemtypes import ITEMTYPE_DEFAULT
Expand Down Expand Up @@ -241,15 +242,7 @@ def ImportMoin19(data_dir=None, markup_out=None, namespace=None):
backend.store(meta, out)

logging.info("PHASE4: Rebuilding the index ...")
indexer.close()
indexer.destroy()
logging.debug("Create index")
indexer.create()
logging.debug("Rebuild index")
indexer.rebuild()
logging.debug("Optimize index")
indexer.optimize_index()
indexer.open()
drop_and_recreate_index(app.storage)

logging.info("Finished conversion!")
if hasattr(conv_out, 'unknown_macro_list'):
Expand Down
3 changes: 2 additions & 1 deletion src/moin/converters/_util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright: 2011 MoinMoin:ThomasWaldmann
# Copyright: 2024 MoinMoin:UlrichB
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
Expand Down Expand Up @@ -120,7 +121,7 @@ def add_lineno(self, elem):
"""
Add a custom attribute (data-lineno=nn) that will be used by Javascript to scroll edit textarea.
"""
if flaskg and flaskg.add_lineno_attr:
if flaskg and getattr(flaskg, 'add_lineno_attr', False):
if self.last_lineno != self.iter_content.lineno:
# avoid adding same lineno to parent and multiple children or grand-children
elem.attrib[html.data_lineno] = self.iter_content.lineno
Expand Down
3 changes: 2 additions & 1 deletion src/moin/converters/docbook_in.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright: 2010 MoinMoin:ValentinJaniaut
# Copyright: 2024 MoinMoin:UlrichB
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
Expand Down Expand Up @@ -57,7 +58,7 @@ class XMLParser(ET.XMLParser):
"""
def _start_list(self, tag, attrib_in):
elem = super(XMLParser, self)._start_list(tag, attrib_in)
if flaskg and flaskg.add_lineno_attr:
if flaskg and getattr(flaskg, 'add_lineno_attr', False):
elem.attrib[html.data_lineno] = self._parser.CurrentLineNumber
return elem

Expand Down
3 changes: 2 additions & 1 deletion src/moin/converters/markdown_in.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright: 2008-2010 MoinMoin:BastianBlank
# Copyright: 2012 MoinMoin:AndreasKloeckner
# Copyright: 2024 MoinMoin:UlrichB
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
Expand Down Expand Up @@ -599,7 +600,7 @@ def __call__(self, data, contenttype=None, arguments=None):

# }}} end Markdown 3.0.0 core.py convert method

add_lineno = bool(flaskg and flaskg.add_lineno_attr)
add_lineno = bool(flaskg and getattr(flaskg, 'add_lineno_attr', False))

# run markdown post processors and convert from ElementTree to an EmeraldTree object
converted = self.do_children(root, add_lineno=add_lineno)
Expand Down
3 changes: 2 additions & 1 deletion src/moin/converters/rst_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright: 2004 Matthew Gilbert <gilbert AT voxmea DOT net>
# Copyright: 2004 Alexander Schremmer <alex AT alexanderweb DOT de>
# Copyright: 2010 MoinMoin:DmitryAndreev
# Copyright: 2024 MoinMoin:UlrichB
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
Expand Down Expand Up @@ -92,7 +93,7 @@ def unknown_departure(self, node):
pass

def open_moin_page_node(self, mointree_element):
if flaskg and flaskg.add_lineno_attr:
if flaskg and getattr(flaskg, 'add_lineno_attr', False):
# add data-lineno attribute for auto-scrolling edit textarea
if self.last_lineno < self.current_lineno:
mointree_element.attrib[html.data_lineno] = self.current_lineno
Expand Down

0 comments on commit b235340

Please sign in to comment.