Giter VIP home page Giter VIP logo

Comments (10)

icebob avatar icebob commented on June 11, 2024

Yes, you can check here: https://github.com/moleculerjs/moleculer-examples/blob/master/conduit/services/articles.service.js#L45
Here the favorited is just a virtual field but it calls other services to collect the data.

from moleculer-db.

jbonnett92 avatar jbonnett92 commented on June 11, 2024

Thank you!
How would I go about populating the virtual field? I did try this:

messages(ids, conversations, rule, ctx) {
	return this.Promise.all(conversations.map(conversation => ctx.call("messages.has", { conversation: conversation._id.toString() }).then(res => conversation.messages = res)));
},
has: {
	params: {
		conversation: { type: "string" }
	},
	handler(ctx) {
		let params = {
			sort: ["createdAt"],
			populate: ["author"],
			query: { conversation: ctx.params.conversation }
		};

		return this.adapter.find(params);
	}
},

Although it just returns the non populated data.

from moleculer-db.

jbonnett92 avatar jbonnett92 commented on June 11, 2024

Ahh I forgot to transform the result return this.adapter.find(params).then(doc => this.transformDocuments(ctx, params, doc));

from moleculer-db.

jbonnett92 avatar jbonnett92 commented on June 11, 2024

Do you know why a service wouldn't generate new data on a request? I made a request to get a conversation and then another to get a different one although the response was the same. Looking at the metrics the second request it doesn't call all services and some are in yellow and have a * net to it where as the first request didn't.

from moleculer-db.

icebob avatar icebob commented on June 11, 2024

it means, the response comes from the cache. If you got the same result for different request means, you should fine-tune the cache key fields. More info: http://moleculer.services/docs/0.13/caching.html#Cache-keys

from moleculer-db.

jbonnett92 avatar jbonnett92 commented on June 11, 2024

I don't have caching fields added. So it shouldn't cache, I purposely removed them for development.

from moleculer-db.

icebob avatar icebob commented on June 11, 2024

But the yellow * means the response came from cache

from moleculer-db.

jbonnett92 avatar jbonnett92 commented on June 11, 2024

It turns out I had this in my config which was the problem:

cacher: {
	type: "memory",
	options: {
		maxParamsLength: 100
	}
},

The weird thing is that it wasn't caching everything and as I said I removed the cache fields so is that strange behaviour?

Just in case you're wondering I'm working on a chat application :) video here I made it with VueJS and VueX, it's an SPA too.

from moleculer-db.

icebob avatar icebob commented on June 11, 2024

Yes, this config enable caching, and moleculer-db base query actions have enabled caching by default. But if you extend it with custom actions they won't be cached by default, just if you set it.

Nice project. Is it a private or public project?
I started a kanban project with the same tech stack :). But I stuck in the authentications :(

from moleculer-db.

jbonnett92 avatar jbonnett92 commented on June 11, 2024

It's a private project for now, nothing to say it won't become public though!

from moleculer-db.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.