mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-06-25 10:54:08 +00:00
fix performance issues
This commit is contained in:
parent
75079a790c
commit
2f0e2a9e24
3 changed files with 100 additions and 55 deletions
|
|
@ -227,9 +227,16 @@ Future<void> finishStartedPreprocessing() async {
|
||||||
if (!service.originalPath.existsSync() &&
|
if (!service.originalPath.existsSync() &&
|
||||||
!service.uploadRequestPath.existsSync()) {
|
!service.uploadRequestPath.existsSync()) {
|
||||||
if (service.storedPath.existsSync()) {
|
if (service.storedPath.existsSync()) {
|
||||||
// media files was just stored..
|
// media file was stored, we can recover tempPath from storedPath and upload it.
|
||||||
|
try {
|
||||||
|
if (!service.tempPath.existsSync()) {
|
||||||
|
service.storedPath.copySync(service.tempPath.path);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
Log.error('Error recovering tempPath from storedPath: $e');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if (mediaFile.reuploadRequestedBy != null) {
|
if (mediaFile.reuploadRequestedBy != null) {
|
||||||
Log.warn(
|
Log.warn(
|
||||||
'Reupload requested for ${mediaFile.mediaId} but files are missing. Cancelling reupload but keeping record.',
|
'Reupload requested for ${mediaFile.mediaId} but files are missing. Cancelling reupload but keeping record.',
|
||||||
|
|
@ -268,6 +275,7 @@ Future<void> finishStartedPreprocessing() async {
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Log.info(
|
Log.info(
|
||||||
'Finishing started preprocessing of ${mediaFile.mediaId} in state ${mediaFile.uploadState}.',
|
'Finishing started preprocessing of ${mediaFile.mediaId} in state ${mediaFile.uploadState}.',
|
||||||
);
|
);
|
||||||
|
|
@ -434,14 +442,38 @@ Future<void> _startBackgroundMediaUploadInternal(
|
||||||
if (mediaService.mediaFile.uploadState == UploadState.initialized ||
|
if (mediaService.mediaFile.uploadState == UploadState.initialized ||
|
||||||
mediaService.mediaFile.uploadState == UploadState.preprocessing) {
|
mediaService.mediaFile.uploadState == UploadState.preprocessing) {
|
||||||
Log.info(
|
Log.info(
|
||||||
'Hanlding media file ${mediaService.mediaFile.mediaId} in ${mediaService.mediaFile.uploadState}',
|
'Handling media file ${mediaService.mediaFile.mediaId} in ${mediaService.mediaFile.uploadState}',
|
||||||
);
|
);
|
||||||
|
|
||||||
await mediaService.setUploadState(UploadState.preprocessing);
|
await mediaService.setUploadState(UploadState.preprocessing);
|
||||||
|
|
||||||
if (!mediaService.tempPath.existsSync()) {
|
if (!mediaService.tempPath.existsSync()) {
|
||||||
|
if (mediaService.storedPath.existsSync()) {
|
||||||
|
try {
|
||||||
|
mediaService.storedPath.copySync(mediaService.tempPath.path);
|
||||||
|
} catch (e) {
|
||||||
|
Log.error('Error copying storedPath to tempPath: $e');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
await mediaService.compressMedia();
|
await mediaService.compressMedia();
|
||||||
|
}
|
||||||
if (!mediaService.tempPath.existsSync()) {
|
if (!mediaService.tempPath.existsSync()) {
|
||||||
|
final messages = await twonlyDB.messagesDao.getMessagesByMediaId(
|
||||||
|
mediaService.mediaFile.mediaId,
|
||||||
|
);
|
||||||
|
if (messages.isEmpty) {
|
||||||
|
Log.warn(
|
||||||
|
'Media files ${mediaService.mediaFile.mediaId} has no original, temp, or stored path. Removing it from DB as files are not existent.',
|
||||||
|
);
|
||||||
|
await twonlyDB.mediaFilesDao.deleteMediaFile(
|
||||||
|
mediaService.mediaFile.mediaId,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
Log.warn(
|
||||||
|
'Media files ${mediaService.mediaFile.mediaId} has no original, temp, or stored path, but messages still reference it. Marking as uploaded to stop retries.',
|
||||||
|
);
|
||||||
|
await mediaService.setUploadState(UploadState.uploaded);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,19 @@ class _MessageInputState extends State<MessageInput> {
|
||||||
widget.textFieldFocus.dispose();
|
widget.textFieldFocus.dispose();
|
||||||
recorderController.dispose();
|
recorderController.dispose();
|
||||||
_nextTypingIndicator?.cancel();
|
_nextTypingIndicator?.cancel();
|
||||||
|
|
||||||
|
// Persist draft message on close
|
||||||
|
final draftText = _textFieldController.text;
|
||||||
|
unawaited(
|
||||||
|
twonlyDB.groupsDao.updateGroup(
|
||||||
|
widget.group.groupId,
|
||||||
|
GroupsCompanion(
|
||||||
|
draftMessage: Value(draftText.isEmpty ? null : draftText),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
_textFieldController.dispose();
|
||||||
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -293,22 +306,15 @@ class _MessageInputState extends State<MessageInput> {
|
||||||
TextField(
|
TextField(
|
||||||
controller: _textFieldController,
|
controller: _textFieldController,
|
||||||
focusNode: widget.textFieldFocus,
|
focusNode: widget.textFieldFocus,
|
||||||
textCapitalization: TextCapitalization.sentences,
|
textCapitalization:
|
||||||
|
TextCapitalization.sentences,
|
||||||
keyboardType: TextInputType.multiline,
|
keyboardType: TextInputType.multiline,
|
||||||
showCursor:
|
showCursor:
|
||||||
_recordingState != RecordingState.recording,
|
_recordingState != RecordingState.recording,
|
||||||
maxLines: 4,
|
maxLines: 4,
|
||||||
minLines: 1,
|
minLines: 1,
|
||||||
onChanged: (value) async {
|
onChanged: (value) {
|
||||||
setState(() {});
|
setState(() {});
|
||||||
await twonlyDB.groupsDao.updateGroup(
|
|
||||||
widget.group.groupId,
|
|
||||||
GroupsCompanion(
|
|
||||||
draftMessage: Value(
|
|
||||||
_textFieldController.text,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
onSubmitted: (_) {
|
onSubmitted: (_) {
|
||||||
_sendMessage();
|
_sendMessage();
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,18 @@ class _MediaViewerViewState extends State<MediaViewerView> {
|
||||||
|
|
||||||
_disposeVideoController();
|
_disposeVideoController();
|
||||||
|
|
||||||
|
// Persist draft message on close
|
||||||
|
final draftText = textMessageController.text;
|
||||||
|
unawaited(
|
||||||
|
twonlyDB.groupsDao.updateGroup(
|
||||||
|
widget.group.groupId,
|
||||||
|
GroupsCompanion(
|
||||||
|
draftMessage: Value(draftText.isEmpty ? null : draftText),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
textMessageController.dispose();
|
||||||
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -834,13 +846,8 @@ class _MediaViewerViewState extends State<MediaViewerView> {
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
controller: textMessageController,
|
controller: textMessageController,
|
||||||
textCapitalization: TextCapitalization.sentences,
|
textCapitalization: TextCapitalization.sentences,
|
||||||
onChanged: (value) async {
|
onChanged: (value) {
|
||||||
await twonlyDB.groupsDao.updateGroup(
|
setState(() {});
|
||||||
widget.group.groupId,
|
|
||||||
GroupsCompanion(
|
|
||||||
draftMessage: Value(textMessageController.text),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
onEditingComplete: () {
|
onEditingComplete: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue