Skip to content

View

flush(view, config)

Flushes the given view's queue.

For non-published views this should always be safe to do (but maybe think about it first, just to make sure) but for published views you should make sure you know what you're doing.

Source code in dataimporter/cli/view.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@view_group.command('flush')
@click.argument('view', type=str)
@with_config()
def flush(view: str, config: Config):
    """
    Flushes the given view's queue.

    For non-published views this should always be safe to do (but maybe think about it
    first, just to make sure) but for published views you should make sure you know what
    you're doing.
    """
    with use_importer(config) as importer:
        view = importer.get_view(view)
        console.log(
            f'Flushing {view.name} view queue, currently has', view.count(), 'IDs in it'
        )
        view.flush()
        console.log(f'{view.name} flushed')

ingest(view, config, everything=False)

On the given view, updates MongoDB with any queued EMu changes and flushes its queue.

Source code in dataimporter/cli/view.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
@view_group.command('ingest')
@click.argument('view', type=str)
@click.option(
    '--everything',
    is_flag=True,
    show_default=True,
    default=False,
    help='Add all records to MongoDB regardless of whether they have changed. This is '
    "primarily useful when a change has been made to a view's filters or "
    'representation',
)
@with_config()
def ingest(view: str, config: Config, everything: bool = False):
    """
    On the given view, updates MongoDB with any queued EMu changes and flushes its
    queue.
    """
    with use_importer(config) as importer:
        console.log(f'Adding changes from {view} view to mongo')
        importer.add_to_mongo(view, everything=everything)
        console.log(f'Added changes from {view} view to mongo')

list_views(config)

List the name of all the views in current use.

Source code in dataimporter/cli/view.py
13
14
15
16
17
18
19
20
@view_group.command('list')
@with_config()
def list_views(config: Config):
    """
    List the name of all the views in current use.
    """
    with use_importer(config) as importer:
        console.log(', '.join(view.name for view in importer.views))

purge(view, config)

Purge non-member and non-publishable records from a view.

Non-publishable records should be handled by the ingest process, but the occurrence of records that stop being members of a view should be much rarer so this needs to be run on a semi-regular basis to account for those.

Source code in dataimporter/cli/view.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
@view_group.command('purge')
@click.argument('view', type=str)
@with_config()
def purge(view: str, config: Config):
    """
    Purge non-member and non-publishable records from a view.

    Non-publishable records should be handled by the ingest process, but the occurrence
    of records that stop being members of a view should be much rarer so this needs to
    be run on a semi-regular basis to account for those.
    """
    with use_importer(config) as importer:
        console.log(f'Purging non-member and non-publishable records from {view}')
        non_member, non_publishable, total_deleted = importer.purge_unsuitable_records(
            view
        )
        console.log(f'{non_member} non-member records found')
        console.log(f'{non_publishable} non-publishable records found')
        console.log(f'{total_deleted} records deleted')

sync(view, config, resync=False)

Updates Elasticsearch with the changes in MongoDB for the given view.

Source code in dataimporter/cli/view.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
@view_group.command('sync')
@click.argument('view', type=str)
@click.option(
    '--resync',
    is_flag=True,
    show_default=True,
    default=False,
    help='Resynchronise all data in Elasticsearch with MongoDB for this view, not just '
    'the records that have changed.',
)
@with_config()
def sync(view: str, config: Config, resync: bool = False):
    """
    Updates Elasticsearch with the changes in MongoDB for the given view.
    """
    with use_importer(config) as importer:
        console.log(f'Syncing changes from {view} view to elasticsearch')
        importer.sync_to_elasticsearch(view, resync=resync)
        console.log(f'Finished with {view}')