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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
acb1e1c
sqlite migrate script
Monirzadeh May 1, 2024
e2aa97a
create time just when bookmark added and modified update if change ha…
Monirzadeh May 1, 2024
7d37ff8
Merge branch 'master' into add-created-time
Monirzadeh May 1, 2024
55673cf
show added and modified time in footer instead of header
Monirzadeh May 1, 2024
cada6fe
Merge branch 'add-created-time' of github.com:Monirzadeh/shiori into …
Monirzadeh May 1, 2024
bca2910
add bun.lockb that missing
Monirzadeh May 1, 2024
428ad58
add migrate for postgres
Monirzadeh May 5, 2024
3eabf23
Merge branch 'master' into add-created-time
Monirzadeh May 5, 2024
3083cc3
add pg support of created time
Monirzadeh May 5, 2024
524ef8f
Merge branch 'master' into add-created-time
Monirzadeh May 7, 2024
3d6c031
change modifed to modifed_at and create to created_at in sqlite
Monirzadeh May 7, 2024
164a9e2
change modifed to modifed_at and create to created_at in postgre
Monirzadeh May 7, 2024
1f53e5c
add created_at to mariadb
Monirzadeh May 7, 2024
e8ea52e
Merge branch 'master' into add-created-time
Monirzadeh May 12, 2024
c56eb54
fix migration file names
Monirzadeh May 12, 2024
bfc21c2
Merge branch 'master' into add-created-time
fmartingr May 12, 2024
2522d29
better variable name and more clear code for add modified time if cre…
Monirzadeh May 12, 2024
bfe3105
Merge branch 'master' into add-created-time
Monirzadeh May 14, 2024
7786437
add unittest
Monirzadeh May 15, 2024
16b2893
add unittest to sure filters work as expected
Monirzadeh May 15, 2024
ff71b6c
index for created_at and modified_at
Monirzadeh May 15, 2024
4ee3d2e
Merge branch 'master' into add-created-time
Monirzadeh May 15, 2024
7d72e91
Merge branch 'master' into add-created-time
Monirzadeh May 18, 2024
966acb1
Merge branch 'master' into add-created-time
Monirzadeh May 26, 2024
101e672
Merge branch 'master' into add-created-time
Monirzadeh May 30, 2024
2c990a3
Merge branch 'master' into add-created-time
Monirzadeh Jun 8, 2024
d6c02fd
build new styles.css
Monirzadeh Jun 8, 2024
243f84d
update swagger documents
Monirzadeh Jun 8, 2024
ffbee63
Merge branch 'master' into add-created-time
Monirzadeh Jun 8, 2024
bd65ec9
make styles
Monirzadeh Jun 8, 2024
c99350d
Merge branch 'master' into add-created-time
Monirzadeh Jun 9, 2024
5c5a54e
change Created and Modified to CreatedAt and ModifiedAt
Monirzadeh Jun 9, 2024
218257f
fix missing Modified
Monirzadeh Jun 9, 2024
9670b48
fix typo
Monirzadeh Jun 9, 2024
4df7436
missing Modified
Monirzadeh Jun 9, 2024
5549fe8
fix typo
Monirzadeh Jun 9, 2024
c17faf4
make swagger
Monirzadeh Jun 9, 2024
9c02e7b
run tests parallel
Monirzadeh Jun 9, 2024
7567214
remove t.Parallel()
Monirzadeh Jun 10, 2024
e1357ce
remove dayjs dependency and combine two function
Monirzadeh Jun 10, 2024
535fccc
better unittest name
Monirzadeh Jun 10, 2024
123d003
fix typo
Monirzadeh Jun 10, 2024
171cea9
diffrnt footer style for login and content page
Monirzadeh Jun 10, 2024
19b9221
use class instead of id
Monirzadeh Jun 10, 2024
aec5089
back parallel
Monirzadeh Jun 12, 2024
62c754b
change duplicate url
Monirzadeh Jun 12, 2024
6af16ee
remvoe run Parallel
Monirzadeh Jun 26, 2024
d11c0e3
Merge branch 'master' into add-created-time
Monirzadeh Jun 26, 2024
7db5cd9
make styles
Monirzadeh Jun 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
create time just when bookmark added and modified update if change ha…
…ppen
  • Loading branch information
Monirzadeh committed May 1, 2024
commit e2aa97a4963e0c52b4a14454b56c8f098adb495a
4 changes: 4 additions & 0 deletions internal/core/processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func ProcessBookmark(deps *dependencies.Dependencies, req ProcessRequest) (book
}

book.HasContent = book.Content != ""
book.Modified = ""
}

// Save article image to local disk
Expand All @@ -137,6 +138,7 @@ func ProcessBookmark(deps *dependencies.Dependencies, req ProcessRequest) (book
}
if err == nil {
book.ImageURL = fp.Join("/", "bookmark", strID, "thumb")
book.Modified = ""
break
}
}
Expand All @@ -154,6 +156,7 @@ func ProcessBookmark(deps *dependencies.Dependencies, req ProcessRequest) (book
return book, true, errors.Wrap(err, "failed to create ebook")
}
book.HasEbook = true
book.Modified = ""
}
}

Expand Down Expand Up @@ -186,6 +189,7 @@ func ProcessBookmark(deps *dependencies.Dependencies, req ProcessRequest) (book
}

book.HasArchive = true
book.Modified = ""
}

return book, false, nil
Expand Down
11 changes: 7 additions & 4 deletions internal/database/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var sqliteMigrations = []migration{
return nil
}),
newFileMigration("0.3.0", "0.4.0", "sqlite/0002_denormalize_content"),
newFileMigration("0.4.0", "0.5.0", "sqlite/0003_created_time"),
}

// SQLiteDatabase is implementation of Database interface
Expand Down Expand Up @@ -138,8 +139,8 @@ func (db *SQLiteDatabase) SaveBookmarks(ctx context.Context, create bool, bookma
// Prepare statement

stmtInsertBook, err := tx.PreparexContext(ctx, `INSERT INTO bookmark
(url, title, excerpt, author, public, modified, has_content)
VALUES(?, ?, ?, ?, ?, ?, ?) RETURNING id`)
(url, title, excerpt, author, public, modified, has_content, created)
VALUES(?, ?, ?, ?, ?, ?, ?, ?) RETURNING id`)
if err != nil {
return errors.WithStack(err)
}
Expand Down Expand Up @@ -213,8 +214,9 @@ func (db *SQLiteDatabase) SaveBookmarks(ctx context.Context, create bool, bookma
// Create or update bookmark
var err error
if create {
book.Created = modifiedTime
err = stmtInsertBook.QueryRowContext(ctx,
book.URL, book.Title, book.Excerpt, book.Author, book.Public, book.Modified, hasContent).Scan(&book.ID)
book.URL, book.Title, book.Excerpt, book.Author, book.Public, book.Modified, hasContent, book.Created).Scan(&book.ID)
} else {
_, err = stmtUpdateBook.ExecContext(ctx,
book.URL, book.Title, book.Excerpt, book.Author, book.Public, book.Modified, hasContent, book.ID)
Expand Down Expand Up @@ -309,6 +311,7 @@ func (db *SQLiteDatabase) GetBookmarks(ctx context.Context, opts GetBookmarksOpt
b.excerpt,
b.author,
b.public,
b.created,
b.modified,
b.has_content
FROM bookmark b
Expand Down Expand Up @@ -681,7 +684,7 @@ func (db *SQLiteDatabase) GetBookmark(ctx context.Context, id int, url string) (
args := []interface{}{id}
query := `SELECT
b.id, b.url, b.title, b.excerpt, b.author, b.public, b.modified,
bc.content, bc.html, b.has_content
bc.content, bc.html, b.has_content, b.created
FROM bookmark b
LEFT JOIN bookmark_content bc ON bc.docid = b.id
WHERE b.id = ?`
Expand Down
1 change: 1 addition & 0 deletions internal/model/bookmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type BookmarkDTO struct {
Excerpt string `db:"excerpt" json:"excerpt"`
Author string `db:"author" json:"author"`
Public int `db:"public" json:"public"`
Created string `db:"created" json:"created"`
Modified string `db:"modified" json:"modified"`
Content string `db:"content" json:"-"`
HTML string `db:"html" json:"html,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions internal/view/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
el: '#content-scene',
mixins: [basePage],
data: {
modified: "$$.Book.Modified$$"
created: "$$.Book.Created$$"
},
methods: {
localtime() {
var strTime = this.modified.replace(" ", "T");
var strTime = this.created.replace(" ", "T");
if (!strTime.endsWith("Z")) {
strTime += "Z";
}
Expand Down
3 changes: 3 additions & 0 deletions internal/webserver/handler-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@
}
}

// Set bookmark modifide
Monirzadeh marked this conversation as resolved.
Show resolved Hide resolved
book.Modified = ""

Check warning on line 364 in internal/webserver/handler-api.go

View check run for this annotation

Codecov / codecov/patch

internal/webserver/handler-api.go#L364

Added line #L364 was not covered by tests
fmartingr marked this conversation as resolved.
Show resolved Hide resolved

// Update database
res, err := h.DB.SaveBookmarks(ctx, false, book)
checkError(err)
Expand Down
Loading