Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIService executes HTTP request without subscription #148

Open
cdasilvacosta opened this issue Oct 30, 2022 · 3 comments
Open

MIService executes HTTP request without subscription #148

cdasilvacosta opened this issue Oct 30, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@cdasilvacosta
Copy link

Hello
I have created a generic component that takes an observable as input and launches it only when I need it (to gain performance). When I call api through the HttpClient of angular, it works very well. But when I use the MIService execute, I see that the M3 api calls run without any subscription on it.
Very simple example :

@Component({
   templateUrl: './test.component.html'
})
export class TestComponent implements OnInit {
   
   constructor(private miService: MIService) {
   }

   ngOnInit(): void {
      this.miService.execute({
         program: 'MNS150MI',
         transaction: 'LstUserData'
      })

   }
}

image

I looked at how the MIService was developed.
From the moment the "execute" method is called, it executes the http request directly and stores the result in an observable.
This can become very problematic and even generate big performance problems.

@cdasilvacosta cdasilvacosta added the bug Something isn't working label Oct 30, 2022
@anhallbe
Copy link
Collaborator

anhallbe commented Nov 4, 2022

Yes! This is indeed a bug. But fixing it may be considered a breaking change, as some existing application may depend on requests being fired without a subscribe(), since that is the way it has always worked.

Will look into this.

But in the meantime, as a workaround you could defer the execution. Example (not tested):

import { defer } from "rxjs";

// This should not fire the request
const response$ = defer(() => this.miService.execute({
    program: 'MNS150MI',
    transaction: 'LstUserData',
}));

// This fires the request
response$.subscribe(response => ...)

@cdasilvacosta
Copy link
Author

Thanks for the answer.

Why not make a major update just to avoid that it impacts the current projects and report this correction in the release notes?

@swuendri
Copy link
Contributor

@anhallbe and @cdasilvacosta, I have prepared a PR #153.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants