Enhancing performance by implementing cache mechanism for storing search results in a table with multiple filtering options using Vue

In my current project, I am utilizing VueJS. However, the issue I am facing is not necessarily exclusive to this framework - but if there is a vue-specific solution available, that would be my preference.

The task at hand involves constructing a table with per-column filters (simple inputs in this instance). The columns are dynamic, as well as the volume of data (thousands of rows, but less than 100,000 entries).

// example data
var columns = ['id', 'title', 'date', 'colour']
var data = [{ id: 1, title: 'Testentry 1', date: '2017-02-21T07:10:55.124Z', colour: 'green'}]

Here lies the challenge: I am iterating through the columns, checking for the existence of a search input. If found, I attempt to filter the data based on the search query. For the ID column, the time complexity is O(n). If I add a title search as well, I can optimize by leveraging the result of the initial query, reducing the amount of data processed significantly.

The search queries are stored in an object called search, and the filtered data is managed as a computed property that updates whenever search changes. The current setup triggers re-evaluation of all search queries, even those that remain unchanged when adjusting just one column's search criteria.

To streamline this process, caching of filtered data for each column may be necessary, ensuring subsequent columns are only queried after the initial filtering stages.

Edit: Below is the code snippet for the filtering logic:

filteredRows () {
  var rows = this.data
  for (var i = 0; i < this.columns.length; i++) {
    var column = this.columns[i].name
    var search = this.tSearch[column]

    if (!search && search.length === 0) continue

    console.log(column + ': ' + ' (' + search + ') -> ' + rows.length)
    rows = _.filter(rows, (row) => {
      var value = '' + row[column]
      value.search(search) > -1
    })
  }

  return rows
}

Answer №1

Perhaps you could consider utilizing a watcher to capture both the previous and current values of an input.

data: function() {
  return {
    valueToMonitor: 'example'
  }
},
computed: {
  ...
},
watch: {
  'valueToMonitor': function (newValue, oldValue) {
    console.log(oldValue); // displays previous value
    console.log(newValue); // displays current value
    // You can then proceed to invoke a function with these arguments to detect any changes
  }
},
....

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Limiting the size of images within a specific section using CSS

When using CSS, I know how to resize images with the code snippets below: img {width:100%; height: auto; } img {max-width: 600px} While this method works effectively, it applies to every image on the page. What I really need is for some images to be ...

Is it possible to verify the presence of an ID with jQuery?

Is it possible to check for the existence of the id 'input-name' before assigning a value to the variable name using a line of code similar to this: var name = $('#input-name').attr("value"); In case the id 'input-name' does ...

The array does not store the ObjectId

I'm trying to implement the favoriting feature following a tutorial, but I'm encountering issues with making it work. Any assistance would be greatly appreciated. Thank you! UserSchema: var UserSchema = new mongoose.Schema({ username: {type ...

What mechanism does package.json use to determine whether you are currently operating in development or production mode?

What is the process for package_json to determine when to load devDependencies as opposed to regular dependencies? How does it differentiate between local development and production environments? ...

Troubleshooting ng-repeat in AngularJS: Multi checkbox filter malfunction

My AngularJS app has multiple age range filters implemented, but one of them is not functioning correctly and I can't figure out why. You can view a functional example here. The various filters are defined as follows: .filter('five', func ...

Adding a version number to the splash screen in Cordova: A step-by-step guide

After successfully integrating the Cordova Splashscreen plugin into my Ionic project, everything is running smoothly. However, I am now looking to dynamically add a version number to the splash screen without manually editing the Splash Screen PNG file e ...

Tips for effectively handling the auth middleware in react.js by utilizing LocalStorage

After making a call to the authentication API, the plan is to save the authentication token in LocalStorage and then redirect to a dashboard that requires token validation for entry. However, an issue arises where the authentication token isn't immedi ...

Resizing Div elements in React

I am currently working on a Drawer navigation feature and I am exploring the option of enabling mouse drag resize functionality. To achieve this, I have included a div element where I listen for the onMouseDown event. Once triggered, I then add an event li ...

Having trouble with Redux's mapStateToProps function?

I'm working on a React component that triggers an AJAX call in the componentWillMount lifecycle method and then stores the fetched data in a Redux store. Here's the code snippet: componentWillMount() { var self = this; var xmlhttp = new XMLH ...

Creating scalable React applications

Can you provide insights on the scalability of React Apps? What recommended approaches are typically employed to effectively handle and generate scalable states in web applications using Reactjs? * ...

Struggling to store a new user in Firebase Database

I have been researching extensively and am struggling to get any data to show up in the firebase database. I am aiming for this specific structure: "my-app-name": { "users": { "uid-of-user": { "email": "<a href="/cdn-cgi/l/email ...

Acquire JSON data from a URL and display it on the webpage

I'm facing an issue where the JSON data I'm trying to fetch from a URL is not displaying due to an uncaught reference error in my code. How can I modify the code to ensure that the data gets shown? var url = "https://fantasy.premierleague.com/ ...

Retrieve information from a JSON file within a Vue.js application rather than entering data manually

I am venturing into the world of Vue.js for the first time. I have created an app that currently relies on manually added data within the script. Now, I am looking to enhance it by fetching data from a JSON file, but I'm unsure about how to proceed wi ...

Vue.js - updating npm to patch version with unclean git working directory

I recently followed a tutorial on how to publish packages to NpmJS. However, I encountered an error when trying to update the package after making changes to the README.MD: npm version patch npm ERR! Git working directory not clean. npm ERR! A .gitignore ...

Tips for showing outcome in the main window after form submission in a showModelDialog box through ajax

I find myself in a challenging situation where the parent window triggers a showModalDialog box to submit a form. Upon submission, the form is sent to a struts2 action which performs some tasks and then redirects back to the parent page, causing a full ref ...

Trigger an event in Vue with specified parameters

I am attempting to emit a function with parameters in the following way. template: ` <div class="searchDropDown"> <div class="dropdown is-active"> <div class="dropdown-trigger"> <button class="button" aria-haspopup=" ...

Guide to converting a string into an undefined type

I've been working on parsing a csv file: let lines = csvData.split(/\r\n|\n/); let headers = lines[0].split(','); for (let i = 1; i < lines.length; i++) { let values = lines[i].split(','); ...

The process of compressing font files (such as ArialMT.ttf) using JSZip is experiencing issues

While zipping images and HTML files works smoothly, I encountered an issue when trying to add font files for CSS. The font file is only 1kb in size, but it cannot be opened. Even after attempting to zip the font without any other files, the problem persis ...

Execute Cheerio selector once the page has finished loading

Hey there! I'm trying to extract the URL value of an iframe on this website: I've checked the view page source but couldn't find the iframe. Looks like it's loaded after the page is fully loaded through JavaScript. Could it be that ...

Make sure to load the HTML content before requesting any input from the user through the prompt function

Could you please help me with a question? I'm looking to load HTML content before prompting the user for input using JavaScript's prompt() function. However, currently the HTML is only loaded after exiting the prompt. Below is the code that I hav ...