Clearing publication content from server - meteor

I am using the "low-level" publication API to publish a temporary collection (not backed by MongoDB).
The published collection is an homemade aggregation which depends on various persistent collections.
Due to business logic, at some point when I want to clear the published collection. This would mean calling this.removed('my-collection', id) for every item in the collection. However I don't want to maintain the list of item in the collection (this would probably be redundant with internal meteor cache anyway).
Is there a simple way to clear a collection from the server's publish code?

Related

How to save reads in a SPA with multiple routes that keep fetching the same data that hasn't changed since?

I'm working on a single page app in VueJS with Firestore and I have different routes (served by different components with their own lifecycle) so I was wondering: if I were to call onSnapshot in all these different components, are the documents going to be fetched once by the first listener and then shared to the others using a local cache, or multiple times, one for each listener? All of this assuming that the documents are not changing.
And if that is true: is there some condition that must be satisfied for the cache to remain valid? For instance: maybe at least one listener must stay active otherwise the cache is invalidated. Meaning that going from one route to another would make this pointless since the component serving the previous route would be destroyed, invalidating the cache that the component serving the next route would use.
If not: what is the strategy commonly used by SPAs? Maybe a global store, such as Vuex, with global onSnapshot listeners that keep the store updated, with all components depending on that store?
I'm aware the Firestore SDK lets you chose whether you would like the data to be fetched from the cache or from the server but that's too much extra hassle in my opinion.
I'd like the library to do it for me: maybe the sdk could use cached data but if some document gets added/removed/modified online, then a realtime ping will invalidate the cache or maybe just those documents that have changed.

Handling documents that don't belong to a collection in Firestore

I have an application that was initially just using a local json server, but I started migrating to Firebase/Firestore recently. With my json server, I had an endpoint that retrieved just an object with the user's custom settings. Those settings will never need to be an array, it will always just be an object. How do I handle that in Firestore where every document is supposed to belong to a collection? Do I just create a collection that will always have 1 object inside? That seems kind of hacky, but I can't think of another solution and I am struggling to figure out how to search for the answer.
EDIT:
I have a lot more data than just this object. Most of my data are arrays that can get very long.
Just create a collection that has one document. You are absolutely obliged to put a document in a collection.
My opinion: if all you have is one object to store, Cloud Firestore is massive overkill for that problem. It's easy to put together, but you are going to pay for document reads that might be cheaper using something a little more straightforward than a massively scalable, cloud hosted, NoSQL, realtime database.

Multiple Questions about meteor pub/sub

I'm new to Meteor. I intend to add a new document to collection(client+server) and let the server pick the change. Then when i need to update my template with the sum total of all the inserts/updates/removes on the collection, i publish the collection from server and subscribe to it on client.
Once we publish something, can we subscribe, stop subscription and then subscribe again? I intend to subscribe only when the 'add document' button on client is pressed. In the function that processes such a click, I intend to insert, then call the method on server to publish and then subscribe. Is that a proper way of going about this?
Is there a way to simplify this? like i put the insert or update of a document in to the client side collection and just let Meteor deal with updating the server side collection and then updating the client side template?
It appears to me, from what little I learnt, that for some use-cases that I have, need publishing at each click. I've done this to update the reactive table to list the current folder's contents each time a folder is selected. So a Publish on server checks for contents in the collection for that folder as parent and returns it. Each new select of a folder means new publish. Can something be done to simplify this?
You're overcomplicating one of the core concepts behind Meteor: reactivity. Here are some clarifications to your 3 questions though:
This isn't something you need to worry about. Once you publish a
collection, or subset of your collection, it's published to all
connected clients. When you're subscribed to said publication, any
updates that are made are reactively pulled down to all connected
clients with that subscription. So if I add a document to a
collection I'm subscribed to, say a task list, it's going to be
reactively sent down to any client that's subscribed to it,
including my own.
Meteor has something called latency compensation which immediately
updates the user interface, and as long as it matches what the
server says, the insert appears to happen instantaneously. This
behavior is what Meteor does by default if you insert to a
collection from the client, as long as your insert is approved (i.e.
as long as the client has permissions to insert to that collection).
You don't need to republish every time. As long as you're publishing
the documents in the collection you need, and you're subscribed on
the client, any new documents that meet the criteria of your Mongo
selectors and return statements on the client will be available to
you and your UI will be updated automatically.

Send data to a specific solr collection

I would like to know how to send a data to a specific collection into running Solr instance (actually into running SolrCloud instance).
I've started a SolrCloud instance with a bunch of hand-made collections (using SolrCloud Collections REST API) and hence wanted to send some data to a specific collection in order to easily distinct one sort of data from another. Unfortunately I didn't find a way to do that..
It it possible? If it is than how?
The collection is part of the URL you're using when querying any server, usually located under http://localhost:8983/solr/<collection name>/. If you're querying the products collection to retrieve all documents, the url would be http://localhost:8983/solr/products/select?q=*:*. The same goes for updating a collection, POST your content to http://localhost:8983/solr/products/update.
Replace localhost:8983 with one of your own server host/port combinations.
You can also see further examples in the Getting Started with Solr Cloud tutorial.

Static list<User> VS DataBase for Online Users in Asp.Net?

I'm building ASP.Net MVC application "kinda Game" which deal a lot with online users.
I made Ajax request fired every "10s" to some Action to keep user online when he keeps site open.
this Action update LastActivityDate for this User - ((in static List and DataBase)).
So the Question is :
Is it better to store Online Users in static list and write some code when user log in to add him to that list and then keep manage this list every "10s" to kick out the offline users.
Or the best is to load online users
from DataBase whenever i want OnlineUsers.
note: I'm using technique from this SO Question to do some periodically tasks like re-manage OnlineUsers static list.
First, you wouldn't use a List<User> for this, but rather a Dictionary<int,User>, using the user's id as the key, so that you could immediately find the user to update. Second, I think it's probably a mixture of both. You keep a cached copy of the current users, periodically refreshed from the DB, and persist the data (asynchronously, if necessary) to the DB. You might want to think about a custom persistence class for Users that encapsulates this behavior if you find that you're doing this sort of operation in various places in your code.
If you intend on having a large number of users, and you would need to pull data from the DB frequently, it may be better to store a list of users in the Cache. Obviously this will be stored in the server's memory, so you wouldn't want to store a large amount of objects, but if it's just a simple list of online users it shouldn't be an issue.
The scope of static is always the scope of the process that runs in the operating system. So in a desktop application the use of static makes sense. However, I find the use of static a little bit arbitrary for server side applications because you don't control the processes. It's the web server that does this. What if the process ends unexpectedly? Or what if there are many processes that serve your application?
So, the use of the database is unavoidable. Still, you can the static scope as a temporary cache but you cannot rely on it.

Resources