Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
301 views
in Technique[技术] by (71.8m points)

node.js - What are the implications of forking the EntityManager a large amount of times in Mikro-ORM?

I'm building a back-end web server with Apollo Server Express and Mikro-ORM and following the docs, I found that the fork() method can be used to get a clean entity manager. I've used the function in the config object as part of the context.

const server = new ApolloServer({
    schema,
    context: async ({ req }): Promise<Context> => {
      const context: Context = {
        em: orm.em.fork(),
      }
      const token = req.headers.authorization || ''
      if (token) {
        try {
          const { uid, } = await auth.verifyIdToken(token)
          context.uid = uid
        } catch (err) {
          console.log(err)
        }
      }
      console.log(context);
      return context;
    },
    playground: true 
  });

While logging out the context as shown in the code, I found that all the forks are kept in memory (or it seems to be).

Output:

...
{ em: [EntityManager<743>], uid: 'XtaxEqnngWXklT4xOZUNmHbVO2f2' }
{ em: [EntityManager<744>], uid: 'XtaxEqnngWXklT4xOZUNmHbVO2f2' }
{ em: [EntityManager<745>], uid: 'XtaxEqnngWXklT4xOZUNmHbVO2f2' }
{ em: [EntityManager<746>], uid: 'XtaxEqnngWXklT4xOZUNmHbVO2f2' }
{ em: [EntityManager<747>], uid: 'XtaxEqnngWXklT4xOZUNmHbVO2f2' }

My question is if there will be negative consequences as a result of this at some point and if yes, how do I deal with this issue?

question from:https://stackoverflow.com/questions/65925209/what-are-the-implications-of-forking-the-entitymanager-a-large-amount-of-times-i

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...