Assistance from Meteor for storing Cached Cursors

I have a Template that features a select element allowing users to filter through a collection of Objects displayed on a table. The result of the select is stored in a ReactiveVar, which is then utilized in querying a Helper to retrieve the Objects for the Template.

Template Code

<select id="colorSelect">
    <option val="getRed">getRed</option>
    <option val="getBlack">getBlack</option>
</select>

<table>
     {{#each Objects}}
          /* create table */
    {{/each}}
</table>

JavaScript Code

//onCreated initializing Template ReactiveVar for Object's Color
Template.Object.onCreated(function() {
    this.color = new ReactiveVar("");
});

//event for changing 'color' based on select option
Template.Object.events({
    'change #colorSelect'(e, template) {
         const target = e.target;
         const color = $(target).val();
         template.color.set(color);
   }
});

//Helper method to return Objects
Template.objects.helpers({
    Objects: function() {
        const color = Template.instance().color.get();
        return Objects.find({foo:bar, color:color}).fetch();
    }
});

The functionality works effectively as the table reacts dynamically to the select options. However, I am concerned about the efficiency and whether the framework caches previously retrieved cursor data when a user changes their selection.

One possible approach could be: 1. Conduct an initial find query 2. Filter the main original dataset (an array from fetch call) 3. Return the modified data to the UI Yet, this method might sacrifice reactivity and necessitate table rearrangement with JavaScript.

Another question arises - does Meteor automatically cache cursors or is there a performance difference since it pulls data from MiniMongo, essentially a JSON object?

Would you consider using a reactiveVar paired with a Helper as a standard pattern?

Answer №1

Your code seems to be in great shape and follows the standard practices, so no need to worry about that aspect.

When it comes to efficiency and caching, remember that the client already stores a local copy of server data, called subscriptions, in minimongo. As long as you:

  • Maintain minimal data publishing
  • Avoid constantly subscribing to new data and replacing old ones

You should be all set. :)

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

Error with Cross-Origin Resource Sharing (CORS) upon inserting a parameter within an Express application

I'm completely stumped as to why this isn't functioning properly. My express app is deployed on Heroku and here's the code: var urlMetadata = require('url-metadata') var express = require('express') var cors = require( ...

Triggering createEffect in SolidJS with an external dependency: A guide

Is there a way to use an external dependency to trigger the createEffect function in Solid, similar to React's useEffect dependency array? I am trying to execute setShowMenu when there is a change in location.pathname. const location = useLocation() ...

Implementing pagination in a Node.js application using MongoDB.ORCreating

function implementPaginationForDigitalMigrationJoin(req, res, next) { DigitalMigrationForm.aggregate([ // Join with user_info table { $lookup: { from: DigitalMigrationFormList.collection.name, // other ...

Simple methods to minimize the iteration of array loops in Node.js

First, retrieve the "grid_id" from the "grids" array ( Step 1 ) Next, verify if this "grid_id" is present in the "variationsDB" array ( Step 2 ) Once you have this "grid_id", use it to fetch the "var ...

The issue at hand is that the headers cannot be redefined once they have already been sent

Hello, I have tried numerous solutions but have not been able to resolve the "Can't set headers after they are sent" error in the following simple code. I have spent several days working on this and would greatly appreciate any input you may have. ap ...

Using mongoose to execute a join operation

Currently, I have organized 2 collections named Dates and Streets. The goal is to query Streets using a parameter StreetName, find its unique ID, and then use that ID to query the other collection for dates that match. The route is configured as /wasteDa ...

When using the GET method to load a PHP file via AJAX, the page may not display certain jQuery plugins even after the file

Hello, I am a beginner learning AJAX and JQuery. Maybe this is a silly question, but please bear with me. I am trying to dynamically show data without refreshing the page using AJAX. I have a function loaded in the body tag which handles this. Everything ...

The cookie appears in the callback URL, but does not get stored in the browser's cookie storage

I'm attempting to store the facebookPicUrl image in a cookie. Even though I can see it in the callback request, it's not showing up in the browser's cookie storage. Just to clarify, the session cookie is working fine. auth.route('/auth ...

Find all objects in Mongo that were created during specific hours while using a systematic time format

There are objects stored in a Mongo database with values like: 1477663239000. Using JavaScript, it is possible to convert these values into date format: new Date(1477663239000) // => Date 2016-10-28T14:00:39.000Z Is there a way to query the mongodb t ...

Switching between fixed and unfixed divs causes two absolute divs to alternate

I am currently working on a code to keep a fixed div ("two") in place between two absolute positioned divs ("one" and "footer") while scrolling. However, there is an issue that arises when the browser window is resized. The distance between the footer and ...

Having difficulty getting a basic code to work: ajax method ($.post) with MySQL is not

I am facing an issue with this code not functioning properly. I want to display the result of a MySQL query without sending any data using my simple Ajax code. $('.myClass').on('click',function(){ $.post('resultAll.php'); ...

Tips for uploading images, like photos, to an iOS application using Appium

I am a beginner in the world of appium automation. Currently, I am attempting to automate an iOS native app using the following stack: appium-webdriverio-javascript-jasmine. Here is some information about my environment: Appium Desktop APP version (or ...

Monitoring the health and availability of AWS S3 buckets via API for checking their status

While working on a node.js application, I successfully implemented s3 file upload. However, there have been instances when the s3 bucket goes down for maintenance or other reasons. To address this issue and keep users informed, I wanted to incorporate an A ...

Emphasize the designated drop zone in Dragula

Incorporating the Dragula package into my Angular 2 project has greatly enhanced the drag-and-drop functionality. Bundling this feature has been a seamless experience. Visit the ng2-dragula GitHub page for more information. Although the drag-and-drop fun ...

Automatically selecting a row within Material-UI's data grid using React code

Currently, I am in the process of developing a React web application and utilizing DataGrid from Material-UI by Google. The grid displays based on the user's selection from a select list (e.g., if the select list consists of fruits and the user choose ...

execute the function once the filereader has completed reading the files

submitTCtoDB(updateTagForm:any){ for(let i=0;i<this.selectedFileList.length;i++){ let file=this.selectedFileList[i]; this.readFile(file, function(selectedFileList) { this.submitTC(updateTagForm,selectedFileList); }); } } } ...

Using jQuery to Activate Genuine Events

Is it true that jQuery's trigger() only executes event handlers bound with jQuery? I have some modules that utilize native browser event binding. Although the solution from works for me, I'm curious if there is a built-in way in jQuery to handle ...

What is the best way to trigger the selection options in a dropdown menu with several buttons?

Is it possible to display the options from a select-option tag using a different button? I have either a div or another button. I want to be able to show the list of options from my select tag by clicking this button. Here is my select tag: <select&g ...

Mongo DB - querying elements in nested arrays

I have a unique data structure that looks like this { "level1": [ { "id": 1, "level2": [ [ { "id": 1 ...

Experiencing a 400 error while transitioning from ajax to $http?

I am facing an issue while trying to make a GET request using $http instead of ajax. The call functions perfectly with ajax, but when attempting the same with $http, I encounter a 400 (Bad Request) error. I have referenced the Angular documentation and bel ...