mirror of
https://github.com/wekan/wekan.git
synced 2025-12-16 23:40:13 +01:00
Move every Attachments.findOne() to the ReactiveCache
This commit is contained in:
parent
fe2015735a
commit
3fc9c6efe7
5 changed files with 30 additions and 7 deletions
|
|
@ -66,7 +66,7 @@ function getPrevAttachmentId(currentAttachmentId) {
|
||||||
|
|
||||||
function openAttachmentViewer(attachmentId){
|
function openAttachmentViewer(attachmentId){
|
||||||
|
|
||||||
const attachment = Attachments.findOne({_id: attachmentId});
|
const attachment = ReactiveCache.getAttachment(attachmentId);
|
||||||
|
|
||||||
$("#attachment-name").text(attachment.name);
|
$("#attachment-name").text(attachment.name);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,10 @@ ReactiveCacheServer = {
|
||||||
const ret = CustomFields.find(selector).fetch();
|
const ret = CustomFields.find(selector).fetch();
|
||||||
return ret;
|
return ret;
|
||||||
},
|
},
|
||||||
|
getAttachment(id) {
|
||||||
|
const ret = Attachments.findOne(id);
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
getUser(id) {
|
getUser(id) {
|
||||||
const ret = Users.findOne(id);
|
const ret = Users.findOne(id);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -159,6 +163,16 @@ ReactiveCacheClient = {
|
||||||
const ret = this.__customFields.get(Jsons.stringify(selector));
|
const ret = this.__customFields.get(Jsons.stringify(selector));
|
||||||
return ret;
|
return ret;
|
||||||
},
|
},
|
||||||
|
getAttachment(id) {
|
||||||
|
if (!this.__attachment) {
|
||||||
|
this.__attachment = new DataCache(_id => {
|
||||||
|
const _ret = Attachments.findOne(_id);
|
||||||
|
return _ret;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const ret = this.__attachment.get(id);
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
getUser(id) {
|
getUser(id) {
|
||||||
if (!this.__user) {
|
if (!this.__user) {
|
||||||
this.__user = new DataCache(userId => {
|
this.__user = new DataCache(userId => {
|
||||||
|
|
@ -309,6 +323,15 @@ ReactiveCache = {
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
},
|
},
|
||||||
|
getAttachment(id) {
|
||||||
|
let ret;
|
||||||
|
if (Meteor.isServer) {
|
||||||
|
ret = ReactiveCacheServer.getAttachment(id);
|
||||||
|
} else {
|
||||||
|
ret = ReactiveCacheClient.getAttachment(id);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
getUser(id) {
|
getUser(id) {
|
||||||
let ret;
|
let ret;
|
||||||
if (Meteor.isServer) {
|
if (Meteor.isServer) {
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ Activities.helpers({
|
||||||
return ReactiveCache.getCardComment(this.commentId);
|
return ReactiveCache.getCardComment(this.commentId);
|
||||||
},
|
},
|
||||||
attachment() {
|
attachment() {
|
||||||
return Attachments.findOne(this.attachmentId);
|
return ReactiveCache.getAttachment(this.attachmentId);
|
||||||
},
|
},
|
||||||
checklist() {
|
checklist() {
|
||||||
return Checklists.findOne(this.checklistId);
|
return Checklists.findOne(this.checklistId);
|
||||||
|
|
|
||||||
|
|
@ -151,20 +151,20 @@ if (Meteor.isServer) {
|
||||||
check(fileObjId, String);
|
check(fileObjId, String);
|
||||||
check(storageDestination, String);
|
check(storageDestination, String);
|
||||||
|
|
||||||
const fileObj = Attachments.findOne({_id: fileObjId});
|
const fileObj = ReactiveCache.getAttachment(fileObjId);
|
||||||
moveToStorage(fileObj, storageDestination, fileStoreStrategyFactory);
|
moveToStorage(fileObj, storageDestination, fileStoreStrategyFactory);
|
||||||
},
|
},
|
||||||
renameAttachment(fileObjId, newName) {
|
renameAttachment(fileObjId, newName) {
|
||||||
check(fileObjId, String);
|
check(fileObjId, String);
|
||||||
check(newName, String);
|
check(newName, String);
|
||||||
|
|
||||||
const fileObj = Attachments.findOne({_id: fileObjId});
|
const fileObj = ReactiveCache.getAttachment(fileObjId);
|
||||||
rename(fileObj, newName, fileStoreStrategyFactory);
|
rename(fileObj, newName, fileStoreStrategyFactory);
|
||||||
},
|
},
|
||||||
validateAttachment(fileObjId) {
|
validateAttachment(fileObjId) {
|
||||||
check(fileObjId, String);
|
check(fileObjId, String);
|
||||||
|
|
||||||
const fileObj = Attachments.findOne({_id: fileObjId});
|
const fileObj = ReactiveCache.getAttachment(fileObjId);
|
||||||
const isValid = Promise.await(isFileValid(fileObj, attachmentUploadMimeTypes, attachmentUploadSize, attachmentUploadExternalProgram));
|
const isValid = Promise.await(isFileValid(fileObj, attachmentUploadMimeTypes, attachmentUploadSize, attachmentUploadExternalProgram));
|
||||||
|
|
||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
|
|
@ -177,7 +177,7 @@ if (Meteor.isServer) {
|
||||||
|
|
||||||
Meteor.call('validateAttachment', fileObjId);
|
Meteor.call('validateAttachment', fileObjId);
|
||||||
|
|
||||||
const fileObj = Attachments.findOne({_id: fileObjId});
|
const fileObj = ReactiveCache.getAttachment(fileObjId);
|
||||||
|
|
||||||
if (fileObj) {
|
if (fileObj) {
|
||||||
Meteor.defer(() => Meteor.call('moveAttachmentToStorage', fileObjId, storageDestination));
|
Meteor.defer(() => Meteor.call('moveAttachmentToStorage', fileObjId, storageDestination));
|
||||||
|
|
|
||||||
|
|
@ -804,7 +804,7 @@ Cards.helpers({
|
||||||
|
|
||||||
cover() {
|
cover() {
|
||||||
if (!this.coverId) return false;
|
if (!this.coverId) return false;
|
||||||
const cover = Attachments.findOne(this.coverId);
|
const cover = ReactiveCache.getAttachment(this.coverId);
|
||||||
// if we return a cover before it is fully stored, we will get errors when we try to display it
|
// if we return a cover before it is fully stored, we will get errors when we try to display it
|
||||||
// todo XXX we could return a default "upload pending" image in the meantime?
|
// todo XXX we could return a default "upload pending" image in the meantime?
|
||||||
return cover && cover.link() && cover;
|
return cover && cover.link() && cover;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue