mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	Enhancement: optimize tasks / stats reload (#7402)
This commit is contained in:
		@@ -5565,7 +5565,7 @@
 | 
				
			|||||||
        <source>Other</source>
 | 
					        <source>Other</source>
 | 
				
			||||||
        <context-group purpose="location">
 | 
					        <context-group purpose="location">
 | 
				
			||||||
          <context context-type="sourcefile">src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.ts</context>
 | 
					          <context context-type="sourcefile">src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.ts</context>
 | 
				
			||||||
          <context context-type="linenumber">66</context>
 | 
					          <context context-type="linenumber">67</context>
 | 
				
			||||||
        </context-group>
 | 
					        </context-group>
 | 
				
			||||||
      </trans-unit>
 | 
					      </trans-unit>
 | 
				
			||||||
      <trans-unit id="8187573012244728580" datatype="html">
 | 
					      <trans-unit id="8187573012244728580" datatype="html">
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -71,6 +71,13 @@ describe('StatisticsWidgetComponent', () => {
 | 
				
			|||||||
    expect(reloadSpy).toHaveBeenCalled()
 | 
					    expect(reloadSpy).toHaveBeenCalled()
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  it('should not call statistics endpoint on reload if already loading', () => {
 | 
				
			||||||
 | 
					    httpTestingController.expectOne(`${environment.apiBaseUrl}statistics/`)
 | 
				
			||||||
 | 
					    component.loading = true
 | 
				
			||||||
 | 
					    component.reload()
 | 
				
			||||||
 | 
					    httpTestingController.expectNone(`${environment.apiBaseUrl}statistics/`)
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it('should display inbox link with count', () => {
 | 
					  it('should display inbox link with count', () => {
 | 
				
			||||||
    const mockStats = {
 | 
					    const mockStats = {
 | 
				
			||||||
      documents_total: 200,
 | 
					      documents_total: 200,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
import { HttpClient } from '@angular/common/http'
 | 
					import { HttpClient } from '@angular/common/http'
 | 
				
			||||||
import { Component, OnDestroy, OnInit } from '@angular/core'
 | 
					import { Component, OnDestroy, OnInit } from '@angular/core'
 | 
				
			||||||
import { Observable, Subscription } from 'rxjs'
 | 
					import { first, Observable, Subject, Subscription, takeUntil } from 'rxjs'
 | 
				
			||||||
import { FILTER_HAS_TAGS_ANY } from 'src/app/data/filter-rule-type'
 | 
					import { FILTER_HAS_TAGS_ANY } from 'src/app/data/filter-rule-type'
 | 
				
			||||||
import { ConsumerStatusService } from 'src/app/services/consumer-status.service'
 | 
					import { ConsumerStatusService } from 'src/app/services/consumer-status.service'
 | 
				
			||||||
import { DocumentListViewService } from 'src/app/services/document-list-view.service'
 | 
					import { DocumentListViewService } from 'src/app/services/document-list-view.service'
 | 
				
			||||||
@@ -35,7 +35,7 @@ export class StatisticsWidgetComponent
 | 
				
			|||||||
  extends ComponentWithPermissions
 | 
					  extends ComponentWithPermissions
 | 
				
			||||||
  implements OnInit, OnDestroy
 | 
					  implements OnInit, OnDestroy
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  loading: boolean = true
 | 
					  loading: boolean = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  constructor(
 | 
					  constructor(
 | 
				
			||||||
    private http: HttpClient,
 | 
					    private http: HttpClient,
 | 
				
			||||||
@@ -48,14 +48,15 @@ export class StatisticsWidgetComponent
 | 
				
			|||||||
  statistics: Statistics = {}
 | 
					  statistics: Statistics = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  subscription: Subscription
 | 
					  subscription: Subscription
 | 
				
			||||||
 | 
					  private unsubscribeNotifer: Subject<any> = new Subject()
 | 
				
			||||||
  private getStatistics(): Observable<Statistics> {
 | 
					 | 
				
			||||||
    return this.http.get(`${environment.apiBaseUrl}statistics/`)
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  reload() {
 | 
					  reload() {
 | 
				
			||||||
 | 
					    if (this.loading) return
 | 
				
			||||||
    this.loading = true
 | 
					    this.loading = true
 | 
				
			||||||
    this.getStatistics().subscribe((statistics) => {
 | 
					    this.http
 | 
				
			||||||
 | 
					      .get<Statistics>(`${environment.apiBaseUrl}statistics/`)
 | 
				
			||||||
 | 
					      .pipe(takeUntil(this.unsubscribeNotifer), first())
 | 
				
			||||||
 | 
					      .subscribe((statistics) => {
 | 
				
			||||||
        this.loading = false
 | 
					        this.loading = false
 | 
				
			||||||
        const fileTypeMax = 5
 | 
					        const fileTypeMax = 5
 | 
				
			||||||
        if (statistics.document_file_type_counts?.length > fileTypeMax) {
 | 
					        if (statistics.document_file_type_counts?.length > fileTypeMax) {
 | 
				
			||||||
@@ -105,6 +106,8 @@ export class StatisticsWidgetComponent
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  ngOnDestroy(): void {
 | 
					  ngOnDestroy(): void {
 | 
				
			||||||
    this.subscription.unsubscribe()
 | 
					    this.subscription.unsubscribe()
 | 
				
			||||||
 | 
					    this.unsubscribeNotifer.next(true)
 | 
				
			||||||
 | 
					    this.unsubscribeNotifer.complete()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  goToInbox() {
 | 
					  goToInbox() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,6 +39,12 @@ describe('TasksService', () => {
 | 
				
			|||||||
    expect(req.request.method).toEqual('GET')
 | 
					    expect(req.request.method).toEqual('GET')
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  it('does not call tasks api endpoint on reload if already loading', () => {
 | 
				
			||||||
 | 
					    tasksService.loading = true
 | 
				
			||||||
 | 
					    tasksService.reload()
 | 
				
			||||||
 | 
					    httpTestingController.expectNone(`${environment.apiBaseUrl}tasks/`)
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it('calls acknowledge_tasks api endpoint on dismiss and reloads', () => {
 | 
					  it('calls acknowledge_tasks api endpoint on dismiss and reloads', () => {
 | 
				
			||||||
    tasksService.dismissTasks(new Set([1, 2, 3]))
 | 
					    tasksService.dismissTasks(new Set([1, 2, 3]))
 | 
				
			||||||
    const req = httpTestingController.expectOne(
 | 
					    const req = httpTestingController.expectOne(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -50,6 +50,7 @@ export class TasksService {
 | 
				
			|||||||
  constructor(private http: HttpClient) {}
 | 
					  constructor(private http: HttpClient) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public reload() {
 | 
					  public reload() {
 | 
				
			||||||
 | 
					    if (this.loading) return
 | 
				
			||||||
    this.loading = true
 | 
					    this.loading = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.http
 | 
					    this.http
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user