Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎩 Implementing Complex Filters in Reactive Model Disrupts Pagination and IndexedDB Query Logic #23

Open
veD-tnayrB opened this issue Jan 12, 2024 · 0 comments
Assignees

Comments

@veD-tnayrB
Copy link
Collaborator

Implementing Complex Filters in Reactive Model Disrupts Pagination and IndexedDB Query Logic

Hello Reactive Model Team 🤙

I've encountered an issue while trying to enhance the client-side Reactive Model with additional filter functionalities,
specifically aiming to integrate complex filters like OR, between, startsWith, etc., while preserving the existing
pagination and filtering features.

Issue Description:

  • Functionality Added: An implementation to handle OR operations in filters:
    #processOr = async (params: Record<string, any>[]) => {
    	let items = [];
    	for (let index = 0; index < params.length; index++) {
    		const query = params[index];
    		const response = await this.#parent.store.where(query).toArray();
    		items = [...items, ...response];
    	}
    	return items;
    };

This function successfully handles filters using the OR operator. However, it requires multiple Dexie queries, which
diverges from the original functionality that uses a single IndexedDB request for pagination.

  • File Location: library\modules\entities\collection\local-provider\loader.ts

  • Original Functionality for Comparison:

    where = (params, limit) => {
    	// ... Previous code
    	const collection = Object.keys(specs).length === 0 ? store : (store.where(specs) as unknown);
    	let query = collection as Collection;
    
    	this.#currentLimit = limit;
    	this.#currentOffset = offset;
    
    	if (sortBy) await query.sortBy(sortBy);
    	query = query.filter(i => i.isDeleted !== 1);
    	const values = await query.offset(offset).limit(limit).toArray();
    	return values;
    };

The challenge is integrating this new OR filter logic without disrupting the existing pagination strategy, which is
reliant on a single IndexedDB request. The current approach of handling multiple Dexie queries for complex filters like
OR, between, startsWith, etc., significantly alters the pagination logic, leading to potential incompatibilities and
errors.

Additional Context:

  • This issue is not limited to the OR operator. Similar challenges arise with other Dexie use cases like between,
    startsWith, below, and above.
  • Dexie Documentation for Reference:

Seeking Guidance:

  • How can we implement these complex filters while maintaining efficient and consistent pagination?
  • Are there any recommended approaches or patterns for handling multiple Dexie queries in a way that aligns with the
    existing pagination logic?

I appreciate any insights or suggestions you might have on this matter.

Best regards, Bryant Caballero

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants