https://www.youtube.com/watch?v=Q6CKkQ8xgbc
Pagination: Use `Skip` and `Take` for efficient pagination.
var pagedOrders = await _context.Orders
.Skip((pageNumber - 1) * pageSize)
.Take(pageSize)
.ToListAsync();
Developing high-performance Angular apps requires avoiding common pitfalls. Here are key practices that harm performance and how to fix them.
Developing high-performance applications with Angular requires attention to details that are often overlooked. Here are some common practices that can kill the performance of your Angular application, along with examples of bad code and their corrections.
Change detection is triggered too frequently, affecting performance.
@Component({
selector: 'app-my-component',
templateUrl: './my-component.component.html',
})
export class MyComponent {
@Input() data: any;
}
Use the OnPush
strategy in components where possible. This makes change detection occur only when the component's input changes.
@Component({
selector: 'app-my-component',
templateUrl: './my-component.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class MyComponent {
@Input() data: any;
}
Direct DOM manipulations can be inefficient and hard to manage.
ngAfterViewInit() {
document.getElementById('elementId').style.color = 'blue';
}
Use Angular’s Renderer2
to manipulate the DOM more efficiently.
import { Renderer2 } from '@angular/core';
constructor(private renderer: Renderer2) {}
ngAfterViewInit() {
const element = this.renderer.selectRootElement('#elementId');
this.renderer.setStyle(element, 'color', 'blue');
}
Pipes that perform heavy operations can be re-executed frequently, hurting performance.
@Pipe({
name: 'heavyPipe',
pure: false
})
export class HeavyPipe implements PipeTransform {
transform(value: any): any {
// Heavy transformation logic
}
}
Use pure pipes (pure: true
) for lightweight operations or avoid pipes for heavy operations.
@Pipe({
name: 'heavyPipe',
pure: true
})
export class HeavyPipe implements PipeTransform {
transform(value: any): any {
// Light transformation logic
}
}
Loading all modules and components at initialization can delay loading time.
@NgModule({
declarations: [AppComponent, FeatureComponent],
imports: [BrowserModule, FeatureModule],
bootstrap: [AppComponent]
})
export class AppModule {}
Use lazy loading for modules that are not immediately needed.
const routes: Routes = [
{ path: 'feature', loadChildren: () => import('./feature/feature.module').then(m => m.FeatureModule) }
];
Not cancelling subscriptions can lead to memory leaks.
ngOnInit() {
this.myService.myObservable.subscribe(value => {
// Do something with value
});
}
Use the async
pipe or manage subscriptions with takeUntil
or Subscription
.
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Component({
selector: 'app-my-component',
templateUrl: './my-component.component.html',
styleUrls: ['./my-component.component.css']
})
export class MyComponent implements OnDestroy {
private destroy$ = new Subject<void>();
constructor(private myService: MyService) {
this.myService.getData()
.pipe(takeUntil(this.destroy$))
.subscribe(data => {
// Handle the data
});
}
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
}
For Angular 16+ use takeUntilDestroyed
.
import { Component, OnDestroy } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
@Component({
selector: 'app-my-component',
templateUrl: './my-component.component.html',
styleUrls: ['./my-component.component.css']
})
export class MyComponent implements OnInit, OnDestroy {
constructor(private myService: MyService) {
}
ngOnInit(): void {
this.myService.getData()
.pipe(takeUntilDestroyed(this))
.subscribe(data => {
// Handle the data
});
}
ngOnDestroy() {
}
}
Registering too many providers in the root module increases the bundle size.
@NgModule({
providers: [MyService]
})
export class AppModule {}
Register providers only where they are necessary.
@NgModule({
providers: [MyService] // Register only where necessary
})
export class FeatureModule {}
Using JIT (Just-in-Time) compilation can be less efficient.
// No specific configuration for AOT
Configure the application to use AOT (Ahead-of-Time) compilation.
{
"projects": {
"my-app": {
"architect": {
"build": {
"options": {
"aot": true
}
}
}
}
}
}
Unoptimized bundles increase loading time.
// Default Angular CLI configuration
Use tools like Webpack and Angular CLI build configurations to optimize bundles.
{
"projects": {
"my-app": {
"architect": {
"build": {
"configurations": {
"production": {
"optimization": true,
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"vendorChunk": false,
"buildOptimizer": true
}
}
}
}
}
}
}
By following these practices and corrections, you can significantly improve the performance of your Angular application, making it more efficient and responsive.
OLX, like many large-scale online platforms, employs a variety of data structures and technologies to manage its data effectively. While specific details about OLX's internal architecture are not publicly disclosed, we can infer some common data structures and technologies used in similar applications:
These data structures and technologies help OLX manage large volumes of data efficiently, ensuring that users can quickly access and interact with the platform.
https://www.codewars.com/kata/search/csharp
https://edabit.com/challenges/csharp
https://www.w3resource.com/csharp-exercises/basic-algo/index.php
https://www.roundthecode.com/dotnet-coding-challenges
https://www.fullstack.cafe/interview-questions/net-core
https://coddy.tech/courses/coding_problems
public async Task<bool> CapitalItemFileUploadtoCloud(IFormFileCollection _lstFiles, string _strIncidentId)
{
var blobServiceClient = new BlobServiceClient(strAzureConnectionString);
try
{
bool _blnResult = false;
var blobContainerClient = blobServiceClient.GetBlobContainerClient(strEnvironment); // Container reference
// Create the container if it doesn't exist
await blobContainerClient.CreateIfNotExistsAsync();
foreach (var file in _lstFiles)
{
if (file.Length > 0)
{
// Create a reference to the blob within the container
var blobClient = blobContainerClient.GetBlobClient($"{_strIncidentId}/{file.FileName}");
// Upload the file to the blob
using (var stream = new MemoryStream())
{
try
{
stream.Seek(0, SeekOrigin.Begin);
await blobClient.UploadAsync(stream, new BlobHttpHeaders { ContentType = file.ContentType });
_blnResult = true; // Set result to true if upload succeeds
}
catch (Exception uploadEx)
{
// Handle exceptions during upload
Console.WriteLine($"Upload failed: {uploadEx.Message}");
_blnResult = false;
}
}
}
}
return _blnResult;
}
catch (Exception ex)
{
// Handle exceptions during setup or container operations
Console.WriteLine($"An error occurred: {ex.Message}");
return false;
}
}
https://www.aspirantsclass.com/2023/03/tspsc-group-2-exam-100-days-study-plan.html
SELECT
EmployeeNumber,
COUNT(*) as CountOfDuplicates
FROM
profiles
GROUP BY
EmployeeNumber
HAVING
COUNT(*) > 1;
1.app initilizer
2.ngrx state management.
3.observable(i have admin access batch update using observable(observables)).
4.difference and obseravable and promises
5.how you did jwt in apis side how you consumed in angular side
what happen after expire token
6.change button syntax to be
1.in the center
2.open modal popup
3.hide the button
add firebase to the angular application
ng add @angular/fire
https://www.youtube.com/watch?v=O0uVYhRE850&list=PL1UHgDbN7Tm4SZ6yLE9yDI-YDtf02uc7d
https://github.com/dcyuksel/Result