<commit_before>import { getPrimaryFieldOfPrimaryKey } from '../../../rx-schema';
import type { MangoQuery, PreparedQuery, RxJsonSchema, RxStorageQueryResult } from '../../../types';
import { clone, ensureNotFalsy } from '../../../util';
import { pouchSwapIdToPrimaryString } from '../../pouchdb';
import { preparePouchDbQuery } from '../../pouchdb/pouch-statics';
import { DEXIE_DOCS_TABLE_NAME, stripDexieKey } from '../dexie-helper';
import { RxStorageDexieStatics } from '../rx-storage-dexie';
import type { RxStorageInstanceDexie } from '../rx-storage-instance-dexie';
import { generateKeyRange } from './pouchdb-find-query-planer/indexeddb-find';
import { planQuery } from './pouchdb-find-query-planer/query-planner';


/**
 * Use the pouchdb query planner to determine which index
 * must be used to get the correct documents.
 * @link https://www.bennadel.com/blog/3258-understanding-the-query-plan-explained-by-the-find-plugin-in-pouchdb-6-2-0.htm
 */
export function getPouchQueryPlan<RxDocType>(
    schema: RxJsonSchema<RxDocType>,
    query: MangoQuery<RxDocType>
) {
    const primaryKey = getPrimaryFieldOfPrimaryKey(schema.primaryKey);

    /**
     * Store the query plan together with the prepared query
     * to improve performance
     * We use the query planner of pouchdb-find.
     */
    const pouchCompatibleIndexes = [
        // the primary key is always a free index
        {
            ddoc: null as any,
            name: '_all_docs',
            type: 'special',
            def: {
                fields: [
                    {
                        '_id': 'asc'
                    }
                ] as any[]<commit_msg>ADD TODO for improved indexeddb performance<commit_after>import { getPrimaryFieldOfPrimaryKey } from '../../../rx-schema';
import type { MangoQuery, PreparedQuery, RxJsonSchema, RxStorageQueryResult } from '../../../types';
import { clone, ensureNotFalsy } from '../../../util';
import { pouchSwapIdToPrimaryString } from '../../pouchdb';
import { preparePouchDbQuery } from '../../pouchdb/pouch-statics';
import { DEXIE_DOCS_TABLE_NAME, stripDexieKey } from '../dexie-helper';
import { RxStorageDexieStatics } from '../rx-storage-dexie';
import type { RxStorageInstanceDexie } from '../rx-storage-instance-dexie';
import { generateKeyRange } from './pouchdb-find-query-planer/indexeddb-find';
import { planQuery } from './pouchdb-find-query-planer/query-planner';


/**
 * Use the pouchdb query planner to determine which index
 * must be used to get the correct documents.
 * @link https://www.bennadel.com/blog/3258-understanding-the-query-plan-explained-by-the-find-plugin-in-pouchdb-6-2-0.htm
 * 
 * 
 * TODO use batched cursor
 * @link https://nolanlawson.com/2021/08/22/speeding-up-indexeddb-reads-and-writes/
 */
export function getPouchQueryPlan<RxDocType>(
    schema: RxJsonSchema<RxDocType>,
    query: MangoQuery<RxDocType>
) {
    const primaryKey = getPrimaryFieldOfPrimaryKey(schema.primaryKey);

    /**
     * Store the query plan together with the prepared query
     * to improve performance
     * We use the query planner of pouchdb-find.
     */
    const pouchCompatibleIndexes = [
        // the primary key is always a free index
        {
            ddoc: null as any,
            name: '_all_docs',
            type: 'special',
            def: {
                fields: [
                    {
                        '_id': 'asc'
                    }
                ] as any[]
{'fraction_non_alphanumeric': 0.13058518304987027, 'fraction_numerical': 0.006341885269530124, 'mean_word_length': 2.566289825282631, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 3, 'lorem ipsum': 0, 'www.': 2, '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': '396590', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1023, 'n_words': 248}