Try only fetching last_correspondence when needed
This commit is contained in:
parent
2a0c03eda0
commit
46831c1d19
@ -12,6 +12,7 @@ import { CorrespondentService } from 'src/app/services/rest/correspondent.servic
|
||||
import { ToastService } from 'src/app/services/toast.service'
|
||||
import { CorrespondentEditDialogComponent } from '../../common/edit-dialog/correspondent-edit-dialog/correspondent-edit-dialog.component'
|
||||
import { ManagementListComponent } from '../management-list/management-list.component'
|
||||
import { takeUntil } from 'rxjs'
|
||||
|
||||
@Component({
|
||||
selector: 'pngx-correspondent-list',
|
||||
@ -63,6 +64,26 @@ export class CorrespondentListComponent extends ManagementListComponent<Correspo
|
||||
)
|
||||
}
|
||||
|
||||
public reloadData(): void {
|
||||
this.isLoading = true
|
||||
this.service
|
||||
.listFiltered(
|
||||
this.page,
|
||||
null,
|
||||
this.sortField,
|
||||
this.sortReverse,
|
||||
this._nameFilter,
|
||||
true,
|
||||
{ last_correspondence: true }
|
||||
)
|
||||
.pipe(takeUntil(this.unsubscribeNotifier))
|
||||
.subscribe((c) => {
|
||||
this.data = c.results
|
||||
this.collectionSize = c.count
|
||||
this.isLoading = false
|
||||
})
|
||||
}
|
||||
|
||||
getDeleteMessage(object: Correspondent) {
|
||||
return $localize`Do you really want to delete the correspondent "${object.name}"?`
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ export abstract class ManagementListComponent<T extends ObjectWithId>
|
||||
implements OnInit, OnDestroy
|
||||
{
|
||||
constructor(
|
||||
private service: AbstractNameFilterService<T>,
|
||||
protected service: AbstractNameFilterService<T>,
|
||||
private modalService: NgbModal,
|
||||
private editDialogComponent: any,
|
||||
private toastService: ToastService,
|
||||
@ -81,8 +81,8 @@ export abstract class ManagementListComponent<T extends ObjectWithId>
|
||||
public isLoading: boolean = false
|
||||
|
||||
private nameFilterDebounce: Subject<string>
|
||||
private unsubscribeNotifier: Subject<any> = new Subject()
|
||||
private _nameFilter: string
|
||||
protected unsubscribeNotifier: Subject<any> = new Subject()
|
||||
protected _nameFilter: string
|
||||
|
||||
public selectedObjects: Set<number> = new Set()
|
||||
public togggleAll: boolean = false
|
||||
|
@ -17,9 +17,10 @@ export abstract class AbstractNameFilterService<
|
||||
sortField?: string,
|
||||
sortReverse?: boolean,
|
||||
nameFilter?: string,
|
||||
fullPerms?: boolean
|
||||
fullPerms?: boolean,
|
||||
extraParams?: { [key: string]: any }
|
||||
) {
|
||||
let params = {}
|
||||
let params = extraParams ?? {}
|
||||
if (nameFilter) {
|
||||
params['name__icontains'] = nameFilter
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ class OwnedObjectSerializer(
|
||||
|
||||
|
||||
class CorrespondentSerializer(MatchingModelSerializer, OwnedObjectSerializer):
|
||||
last_correspondence = serializers.DateTimeField(read_only=True)
|
||||
last_correspondence = serializers.DateTimeField(read_only=True, required=False)
|
||||
|
||||
class Meta:
|
||||
model = Correspondent
|
||||
|
@ -253,14 +253,7 @@ class PermissionsAwareDocumentCountMixin(PassUserMixin):
|
||||
class CorrespondentViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
||||
model = Correspondent
|
||||
|
||||
queryset = (
|
||||
Correspondent.objects.prefetch_related("documents")
|
||||
.annotate(
|
||||
last_correspondence=Max("documents__created"),
|
||||
)
|
||||
.select_related("owner")
|
||||
.order_by(Lower("name"))
|
||||
)
|
||||
queryset = Correspondent.objects.select_related("owner").order_by(Lower("name"))
|
||||
|
||||
serializer_class = CorrespondentSerializer
|
||||
pagination_class = StandardPagination
|
||||
@ -279,6 +272,13 @@ class CorrespondentViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
||||
"last_correspondence",
|
||||
)
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
if request.query_params.get("last_correspondence", None):
|
||||
self.queryset = self.queryset.annotate(
|
||||
last_correspondence=Max("documents__created"),
|
||||
)
|
||||
return super().list(request, *args, **kwargs)
|
||||
|
||||
|
||||
class TagViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
||||
model = Tag
|
||||
|
Loading…
x
Reference in New Issue
Block a user