<commit_before>// Copyright 2016 Endless Mobile, Inc.

/* exported OtherGroup */

const {DModel, GObject} = imports.gi;

const Filter = imports.app.interfaces.filter;
const Module = imports.app.interfaces.module;
const Utils = imports.app.utils;

var OtherGroup = new Module.Class({
    Name: 'Filter.OtherGroup',
    Extends: GObject.Object,
    Implements: [Filter.Filter],

    References: {
        'other': {},
    },

    _init: function (props) {
        this.parent(props);
        this._other_model_ids = [];
        this.reference_module('other', (module) => {
            module.connect('models-changed', (selection) => {
                this._other_model_ids = this._other_model_ids.concat(selection.get_models().map(({id}) => id));
                this.emit('filter-changed');
            });
        });
    },

    // Filter implementation
    include_impl: function (model) {
        if (this._other_model_ids.length > 0) {
            return this._other_model_ids.indexOf(model.id) < 0;
        }
        return true;
    },

    // Filter implementation
    modify_xapian_query_impl: function (query) {
        if (this.invert) {
            let ids = this._other_model_ids;
            if (query.ids.length)
                ids = Utils.intersection(query.ids, ids);
            return DModel.Query.new_from_object(query, {ids});
        }
        return DModel.Query.new_from_object(query, {
            excluded_ids: Utils.union(query.excluded_ids, this._other_model_ids),
        });
    },
});<commit_msg>Filter.OtherGroup: Use a Set for performance<commit_after>// Copyright 2016 Endless Mobile, Inc.

/* exported OtherGroup */

const {DModel, GObject} = imports.gi;

const Filter = imports.app.interfaces.filter;
const Module = imports.app.interfaces.module;
const Utils = imports.app.utils;

var OtherGroup = new Module.Class({
    Name: 'Filter.OtherGroup',
    Extends: GObject.Object,
    Implements: [Filter.Filter],

    References: {
        'other': {},
    },

    _init: function (props) {
        this.parent(props);
        this._other_model_ids = new Set();
        this.reference_module('other', (module) => {
            module.connect('models-changed', (selection) => {
                selection.get_models().forEach(({id}) => this._other_model_ids.add(id));
                this.emit('filter-changed');
            });
        });
    },

    // Filter implementation
    include_impl: function (model) {
        return !this._other_model_ids.has(model.id);
    },

    // Filter implementation
    modify_xapian_query_impl: function (query) {
        if (this.invert) {
            let ids = [...this._other_model_ids];
            if (query.ids.length)
                ids = Utils.intersection(query.ids, ids);
            return DModel.Query.new_from_object(query, {ids});
        }
        return DModel.Query.new_from_object(query, {
            excluded_ids: Utils.union(query.excluded_ids, this._other_model_ids),
        });
    },
});
{'fraction_non_alphanumeric': 0.13505361930294907, 'fraction_numerical': 0.003351206434316354, 'mean_word_length': 2.3614864864864864, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1062670', 'n_tokens_mistral': 910, 'n_tokens_neox': 886, 'n_words': 164}