Skip to content
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

feat: store created and modified time separately on database for bookmarks #896

Merged
merged 49 commits into from
Jun 26, 2024

Conversation

Monirzadeh
Copy link
Collaborator

@Monirzadeh Monirzadeh commented May 1, 2024

this PR should done two things:

  1. add created time to the database
  2. modified update if write new content in an exist bookmark.
    any place you will done change in any aspect of bookmark (new archive,content,epub,tags,etc)

in future if we want to update modified time any place in code just set book.modified = "" shiori automatically will update modified time.

TODO:

  • sqlite migrate
  • update model
  • fix logic of update modified time
  • show added time in content page correctly
  • repeat that for postgres database
  • change mariadb update modfied_at same as other database mariadb update modified time when row change that not possible in other database this change in this PR and all use same method now.
  • repeat that for mariadb database
  • add unit tests

Copy link

codecov bot commented May 1, 2024

Codecov Report

Attention: Patch coverage is 80.39216% with 10 lines in your changes missing coverage. Please review.

Project coverage is 35.11%. Comparing base (a3d4a68) to head (19b9221).

Current head 19b9221 differs from pull request most recent head 7db5cd9

Please upload reports for the commit 7db5cd9 to get more accurate results.

Files Patch % Lines
internal/cmd/import.go 0.00% 4 Missing ⚠️
internal/cmd/pocket.go 0.00% 4 Missing ⚠️
internal/cmd/export.go 0.00% 1 Missing ⚠️
internal/webserver/handler-api.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #896      +/-   ##
==========================================
+ Coverage   34.73%   35.11%   +0.38%     
==========================================
  Files          61       61              
  Lines        4054     4061       +7     
==========================================
+ Hits         1408     1426      +18     
+ Misses       2424     2413      -11     
  Partials      222      222              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fmartingr
Copy link
Member

Hey @Monirzadeh is this ready for review? I see items pending.

A side comment for me, would it me much effort renaming the modified column to modified_at and use created_at as creation date column?

@Monirzadeh
Copy link
Collaborator Author

Monirzadeh commented May 6, 2024

mysql is not ready yet
when i fill created with modified value (in maraidb) created (around one or two) second different with modified and i can't find why it happen yet.

ok i will change names column to modified_at and created_at
should i change that in API too or keep that untouch?

@fmartingr
Copy link
Member

mysql is not ready yet when i fill created with modified value (in maraidb) created (around one or two) second different with modified and i can't find why it happen yet.

Let me know if you get stuck with this, I can take a look if you want.

ok i will change names column to modified_at and created_at should i change that in API too or keep that untouch?

Leave the old API as is, we will use the new field in the new API.

RENAME COLUMN modified to created_at;

ALTER TABLE bookmark
ADD COLUMN modified_at TEXT NULL;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified_at is TEXT NULL not

    modified_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,

dose it make any problem?

@Monirzadeh
Copy link
Collaborator Author

Visual change in this PR
Before
1- Before
After created time and modified time is in same day
2- After - created and modified be in same day
After created time and modified time is not in same day
3- After - created and modified not be in sameday

@Monirzadeh
Copy link
Collaborator Author

Monirzadeh commented May 7, 2024

Hi @fmartingr

  • as i see all test pass right now. do we need any specific unit test?
  • about MariaDB i can't done all of them in one migrate (get syntax error while migrate) but when i separate them to multiple stage it work smoothly.
  • in MariaDB change modified time had different method in compare to postgress and sqlite. this PR change that and now all database update modified_at same each other.
  • that dark layer in top of screenshot is related to my browser setup not Shiori change. (created time position change on those screenshot)

@fmartingr fmartingr changed the title feat: Created time added to the database and modified time update if bookmark change feat: store created and modified time for bookmarks May 12, 2024
Copy link
Member

@fmartingr fmartingr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Monirzadeh, good job as ususal. I've left a few comments around for changes.

Also, I'm missing tests for:

  • Ensuring created_at time is set correctly when creating
  • Ensuring modified_at time is set correctly when updating
  • Ensuring created_at filter works properly
  • Ensuring modified_at filter works properly

Let me know if you need help with any of those.

Thank you!

internal/view/content.html Outdated Show resolved Hide resolved
internal/view/content.html Outdated Show resolved Hide resolved
internal/view/content.html Outdated Show resolved Hide resolved
internal/webserver/handler-api.go Outdated Show resolved Hide resolved
internal/webserver/handler-api.go Outdated Show resolved Hide resolved
@fmartingr
Copy link
Member

Forgot to check, but we should probably add indexes in the datetime fields since we are going to rely on those heavily on results.

Copy link
Member

@fmartingr fmartingr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @Monirzadeh !! This is starting to look real good 👏

I have left some requests around. Most are just style things but there are some concerns around. Please take a look and let me know what you think.

@@ -14,7 +14,8 @@ type BookmarkDTO struct {
Excerpt string `db:"excerpt" json:"excerpt"`
Author string `db:"author" json:"author"`
Public int `db:"public" json:"public"`
Modified string `db:"modified" json:"modified"`
Created string `db:"created_at" json:"created"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name this fields CreatedAt / ModifiedAt as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json:"created" should be json:"createdAt" or json:"created_at"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Golang code, CamelCase, for JSON snake_case. Though honestly we could just match everything to the same CamelCase in golang and avoid writting so many json annotations. What do you think?

Copy link
Collaborator Author

@Monirzadeh Monirzadeh Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personalty i am not against none of them. currently we have both of them in json (like imageURL, hasContent or snake case like create_archive and create_ebook)
i am worried about shiori app backward compatibility (if i am not wrong it work with 1.5.5)
as i see there is not specific suggestion in json but usualy use snake_case
@DesarrolloAntonio what do you think?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DesarrolloAntonio what do you think?

Regarding backward compatibility in the Shiori app, I have seen that there is an option to set one or more alternative names. I have never tried it, but theoretically, it should work.`

@SerializedName("createdAt", alternate = ["created_at"])
val createdAt: String?,

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks
So @fmartingr if you like camelCase can go fot that
Beside camelCase or snake_case I think it better to done that in separate PR so later we can refrence that in future issue related to API if anybody ask.
I already use camelCase in this PR

@@ -38,6 +37,9 @@
<div id="content" dir="auto" v-pre>
$$.HTML$$
</div>
<div id="footer">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be a <footer> element rather than a div#footer ?

Copy link
Collaborator Author

@Monirzadeh Monirzadeh Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently we have footer for two place Version in login page and here.
do you want two diffrent footer style?
.footer and another content-footer?

footer {
color: var(--color);
}

and

	#footer {
		width: 100%;
		padding: 20px;
		max-width: 840px;
		margin-bottom: 16px;
		background-color: var(--contentBg);
		border: 1px solid var(--border);
		display: flex;
		flex-flow: column;
		align-items: center;

		#metadata {
			display: flex;
			flex-flow: row wrap;
			text-align: center;
			font-size: 16px;
			color: var(--colorLink);
			&:nth-child(1) {
				justify-content: flex-start;
			}

			&:nth-child(2) {
				justify-content: flex-end;
			}

			&[v-cloak] {
				visibility: hidden;
			}
		}

		#title {
			padding: 8px 0;
			grid-column-start: 1;
			grid-column-end: -1;
			font-size: 36px;
			font-weight: 700;
			word-break: break-word;
			hyphens: none;
			text-align: center;
		}

		#links {
			display: flex;
			flex-flow: row wrap;

			a {
				padding: 0 4px;
				color: var(--color);
				text-decoration: underline;

				&:hover,
				&:focus {
					color: var(--main);
				}
			}
		}
	}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is 171cea9 what you want?

internal/view/content.html Outdated Show resolved Hide resolved
flex-flow: column;
align-items: center;

#metadata {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using IDs for styling, use classes instead.

Copy link
Collaborator Author

@Monirzadeh Monirzadeh Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it what you want? 19b9221
i remove some duplicate style and i can review other part and change them to class too. at least in content page.

the metadata color not much readable in light mode (look at the color of added time in light mode)
i test color like normal text (black) but not good looking. i thinking about make this a little darker in light mode. any suggestion?

Copy link
Collaborator Author

@Monirzadeh Monirzadeh Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as you see in light mode it is not readable enough

dark
light

Comment on lines 431 to 432
func testModifiedTimeUpdate(t *testing.T, db DB) {
ctx := context.TODO()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this test uses time.Sleep let's run it in parallel to avoid blocking other tests.

Suggested change
func testModifiedTimeUpdate(t *testing.T, db DB) {
ctx := context.TODO()
func testModifiedTimeUpdate(t *testing.T, db DB) {
t.Parallel()
ctx := context.TODO()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't see those error in local system that show me that here 9c02e7b for example in golangci-lint

Comment on lines 458 to 459
func testModifiedAndCreateTimeFilter(t *testing.T, db DB) {
ctx := context.TODO()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this test uses time.Sleep let's run it in parallel to avoid blocking other tests.

Suggested change
func testModifiedAndCreateTimeFilter(t *testing.T, db DB) {
ctx := context.TODO()
func testModifiedAndCreateTimeFilter(t *testing.T, db DB) {
t.Parallel()
ctx := context.TODO()

internal/database/database_test.go Outdated Show resolved Hide resolved
internal/database/database_test.go Outdated Show resolved Hide resolved
@Monirzadeh
Copy link
Collaborator Author

@fmartingr
as you see when i use t.Parallel() when two test run side by side than number and id of item in second test can be diffident so it can give use false negative and affect by each test run. for example this time it failed in Linux but other pass that i think it is not related to the platform
how do you think i should solve that.

@fmartingr
Copy link
Member

@fmartingr as you see when i use t.Parallel() when two test run side by side than number and id of item in second test can be diffident so it can give use false negative and affect by each test run. for example this time it failed in Linux but other pass that i think it is not related to the platform how do you think i should solve that.

Ok I was thinking that we received a new empty database on each run but right now that's only true for SQLite (not for Postgres/Mysql). Let's remove the t.Parallel for now but please add a TODO comment:

// TODO: Consider using `t.Parallel()` once we have automated database tests spawning databases using testcontainers.

@fmartingr fmartingr changed the title feat: store created and modified time for bookmarks feat: store created and modified time separately on database for bookmarks Jun 26, 2024
@fmartingr fmartingr merged commit 4a5564d into go-shiori:master Jun 26, 2024
9 checks passed
@Monirzadeh Monirzadeh deleted the add-created-time branch June 26, 2024 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants