-
Notifications
You must be signed in to change notification settings - Fork 360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix v2.8.1 saving issues #1473
Fix v2.8.1 saving issues #1473
Conversation
harshad1
commented
Oct 20, 2021
•
edited by gsantner
Loading
edited by gsantner
- Merge Document and DocumentIO classes, debloat
- flush() after write()
- less save/read calls in activitiy lifecycle
- ..
app/src/main/java/net/gsantner/markor/activity/DocumentEditFragment.java
Show resolved
Hide resolved
app/src/main/java/net/gsantner/markor/activity/DocumentEditFragment.java
Show resolved
Hide resolved
Issue is that the file is not written before it is read. The text sent to disk in |
merge it now and release update right away? |
No. After further testing, I am still seeing the issue.
These changes help, but don't fix the underlying problem.
Oct. 21, 2021 01:12:16 Gregor Santner ***@***.***>:
… merge it now and release update right away?
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub[#1473 (comment)], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AAOZ3TEFJVKTV5RIXL66EMDUH7DN5ANCNFSM5GKSP25A].
Triage notifications on the go with GitHub Mobile for iOS[https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675] or Android[https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub]. [data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFQAAABUCAYAAAAcaxDBAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAAySURBVHic7cEBDQAAAMKg909tDjegAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAeDVulAABbzDScQAAAABJRU5ErkJggg==###24x24:true###][Tracking image][https://github.com/notifications/beacon/AAOZ3TAYZLIDCL2ZIHWTUHLUH7DN5A5CNFSM5GKSP25KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOHCDO6XA.gif]
|
I think we numerous times reworked file saving but might be the time we need to completly rethink it. Though it's a lot of work, and prone to produce more issues. |
This issue is weirder than I thought.
|
then maybe cached string in Document, saveinstancestate or textview? |
Stranger yet:
|
What are the uses of the |
I wrote DocumentIO stuff from scratch, including undo/redo history, file saving etc. Over time most stuff got replaced by other means (i.e. undo/redo worked better in the said textview class) |
https://medium.com/androiddevelopers/android-11-storage-faq-78cefea52b7c
I wonder if these are affecting us |
I don't think so it is the issue. Because Android 11 is out some time now and Markor users, including me have used Markor on it for quite a long time without the issue. Btw, could you spot any issue coming from either the cached FileInfo used at filemanager, or the dynamically fetched own FileProvider? These two things are new in Markor v2.8.1. Though the first is only used at filemanager and not has any writing stuff. And the latter also shoule be fine. |
This has evolved into a refactor of Document and DocumentIO. Changes:
Obviously a lot of testing will have to be performed before this is ready. On the bright side, the bug with missing text appears to have gone away? |
assertThat(normalizeTitleForFilename(nd("HelloWorld", "text"))).isEqualTo("HelloWorld"); | ||
assertThat(normalizeTitleForFilename(nd(null, "text\nnewline"))).isEqualTo("text"); | ||
assertThat(normalizeTitleForFilename(nd(null, "sumtext/folder"))).isEqualTo("sumtextfolder"); | ||
assertThat(normalizeTitleForFilename(nd(null, "## hello world"))).isEqualTo("hello world"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Need to restore this test
public static String normalizeFilename(final String name) { | ||
if (TextUtils.isEmpty(name.trim())) { | ||
return "Note " + UUID.randomUUID().toString(); | ||
} else { | ||
return name.replaceAll("[\\\\/:\"´`'*$?<>\n\r@|#]+", "").trim(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs discussion/change before merge. as this is about to be used everywhere for filenames.
suggestion: R.string ("Note" localized) + DateTime YYYY-MM-DD_HHMMSS or something alike
https://stackoverflow.com/a/35352640
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code there was derived from
Your suggestion here is better IMO. datetime is better than uuid. I will make the change this evening.
@harshad1 |
I think it is good to go. I have been using this branch for the last 2 days without any issues. Will made the changes for tests, for the uuid -> datetime change today. We can then merge tomorrow I think. |
Thanks, I want to merge it on the weekend |
I can see that it shortly blinks when swiping the tabs. So looks like it reloaded the file fully and overwrote the textview content, though it's would not be necessary. screenrecord.mp4I didn't change any text in editor, but landed in the writing code: |
} | ||
|
||
public int getHistoryPosition() { | ||
return _historyPosition; | ||
public static boolean testCreateParent(final File file) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this won't work for sdcard, would always returns false when parents not exist.
I ignore it though to get the PR merged fast.
* reload file only if newer modtime (skip unnecassary read operations) * rework SHA512 hashfunction to return a printable hash string (instead of bytes.toString) * fix check to non-duplicate saving code check from: hashunchanged && notWrittenShortlyAgo to ||
Both scenarios are known / expected. case 1: The content being reloaded when not needed.When we switch tabs (or restore a document which is in the background) we need to check if the file contents has changes. If it has changed we need to update the contents, and if there is no change we can just set the contents anyway as the loaded contents == the existing data. We can test if the loaded text == current text if preventing the flash is important. case 2: I didn't change any text in editor, but landed in the writing code.The write is blocked if and only if the same text was written recently (i.e. time delta < small threshold). This was done to ensure that the file seen in the text editor == the contents written to disk. If the text has been changed in the background (by a sync app, for example), I felt that that the correct thing to do is to always write the text as seen in the editor. We can use modtime to be more defensive here. |
@harshad1 I did some improvements to reduce the amount of file write and file read calls, to have no/less unecessary multiple reads/writes. it also makes use of the modtime, as you mentioned in 2) |
Seems ok. But I will test more in the evening. |
app/src/main/java/net/gsantner/markor/activity/DocumentEditFragment.java
Show resolved
Hide resolved
Merging this now and asking users once more to try it as well. "release candidate" |
Cool. Another (probably unrelated) issue that I have noticed is that onPause / onResume / onViewCreated in DocumentEditFragment are called 2x. We need to investigate this as well. |
Possible cause for ^ https://stackoverflow.com/a/49679530/4717438 |
when you are on mainactivity, or editor? on main its due each of quicknote and todo.txt own lifecycle |