fix slow publication

This commit is contained in:
Peter Maquiran
2023-02-27 21:24:34 +01:00
parent 9a1976f543
commit 7e5039b4fa
6 changed files with 147 additions and 216 deletions
@@ -22,8 +22,8 @@ export class ViewPublicationsPage implements OnInit {
showLoader: boolean;
loading: any;
publicationList: Publication[];
item: PublicationFolder;
publicationList: {[key: string]: Publication[] } = {};
publicationItem: {[key: string]: PublicationFolder } = {};
getpublication = [];
error: any;
@@ -47,7 +47,10 @@ export class ViewPublicationsPage implements OnInit {
public p:PermissionService,
private httpErrorHandle: HttpErrorHandle
) {
this.item = new PublicationFolder();
if(!this.publicationList[this.folderId]) {
this.publicationList[this.folderId] = []
this.publicationItem[this.folderId] = new PublicationFolder();
}
}
ngOnInit() {
@@ -55,10 +58,12 @@ export class ViewPublicationsPage implements OnInit {
this.folderId = this.folderId['ProcessId']
}
//this.getPublicationsIds();
if(!this.publicationList[this.folderId]) {
this.publicationList[this.folderId] = []
this.publicationItem[this.folderId] = new PublicationFolder();
}
window['app-view-publications-page-doRefresh'] = this.doRefresh
this.getPublicationDetail();
this.getFromDB();
}
@@ -68,13 +73,16 @@ export class ViewPublicationsPage implements OnInit {
if(typeof(this.folderId) == 'object') {
this.folderId = this.folderId['ProcessId']
}
this.getFromDB();
//setTimeout(()=>{
this.getPublicationDetail();
this.getPublicationsIds();
//}, 100)
if(!this.publicationList[this.folderId]) {
this.publicationList[this.folderId] = []
this.publicationItem[this.folderId] = new PublicationFolder();
}
this.getFromDB();
this.getPublicationDetail();
this.getPublicationsIds();
}
@@ -82,7 +90,6 @@ export class ViewPublicationsPage implements OnInit {
doRefresh =(event) => {
this.getPublicationDetail();
this.getPublicationsIds();
}
@@ -92,50 +99,51 @@ export class ViewPublicationsPage implements OnInit {
getPublicationDetail() {
this.showLoader = true;
this.publications.GetPresidentialAction(this.folderId).subscribe(res=>{
const folderId = this.folderId
this.publications.GetPresidentialAction(folderId).subscribe(res=>{
this.showLoader = false;
this.item = res;
this.publicationItem[folderId] = res
this.storage.set(folderId+"name", res)
}, (error) => {
this.showLoader = false;
// this.httpErroHandle.httpStatusHandle(error)
});
}
getPublicationsIds() {
async getPublicationsIds() {
this.showLoader = true;
const folderId = this.folderId
this.publications.GetPublicationsImages(this.folderId).subscribe(res => {
this.publicationList = new Array();
res.forEach(element => {
this.publications.GetPublicationById(element).subscribe(ress => {
let item: Publication = this.publicationPipe.itemList(ress)
this.publicationList.push(item);
})
});
this.storage.remove(folderId);
this.storage.set(this.folderId, this.publicationList);
this.getpublication = this.publicationList;
try {
const res = await this.publications.GetPublicationsImages(folderId).toPromise();
let publicationList = []
for (let element of res) {
let ress = await this.publications.GetPublicationById(element).toPromise();
let item: Publication = this.publicationPipe.itemList(ress)
publicationList.push(item);
}
this.showLoader = false;
},() => {
this.publicationList[folderId] = publicationList
this.storage.set(folderId, publicationList);
this.getpublication = publicationList;
} catch(error) {
this.showLoader = false;
this.getFromDB();
});
}
}
getFromDB() {
this.storage.get(this.folderId).then((viewPublications) => {
this.publicationList = viewPublications;
const folderId = this.folderId
this.storage.get(folderId).then((viewPublications) => {
this.publicationList[folderId] = viewPublications
})
this.storage.get(folderId+"name").then((viewPublications) => {
this.publicationItem[folderId] = viewPublications
})
}