Skip to content

Commit

Permalink
Merge pull request #128 from metafates/dev
Browse files Browse the repository at this point in the history
v4.0.1
  • Loading branch information
metafates authored Nov 3, 2022
2 parents ff4e033 + 3d988f7 commit 6e91e01
Show file tree
Hide file tree
Showing 50 changed files with 820 additions and 343 deletions.
2 changes: 1 addition & 1 deletion .idea/mangal.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to
[Semantic Versioning](https://semver.org).

## 4.0.1

This update includes just some bug-fixes and internal improvements. 🥱

- Better caching by [Gache](https://github.com/metafates/gache) library
- Fix comic_info_xml_add_date and comic_info_xml_alternative_date flags #126
- Fix notification that new version is available even though it's the same #125
- Fix config set command doesn't work for string values #127
- Fix json output for `config info -j` command #129
- Fix history and default sources not working well together in TUI
- `config reset` now accepts `--all` flag to reset all config values

## 4.0.0

I've been actively working on this update lately, and I'm finally happy to share the 4th version of Mangal! 🐳
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,13 @@ For example, on __Linux__ it would be `~/.config/mangal/mangal.toml`.
Use env variable `MANGAL_CONFIG_PATH` to set custom config path.
> See `mangal env` to show all available env variables.
| Command | Description |
|----------------------|--------------------------------------------------|
| `mangal config get` | Get config value for specific key |
| `mangal config set` | Set config value for specific key |
| `mangal config info` | List all config fields with description for each |
| `mangal config init` | Write current config to a file |
| Command | Description |
|-----------------------|--------------------------------------------------|
| `mangal config get` | Get config value for specific key |
| `mangal config set` | Set config value for specific key |
| `mangal config reset` | Reset config value for specific key |
| `mangal config info` | List all config fields with description for each |
| `mangal config init` | Write current config to a file |

## Custom scrapers

Expand Down
84 changes: 46 additions & 38 deletions anilist/cache.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package anilist

import (
"github.com/metafates/mangal/cache"
"github.com/metafates/gache"
"github.com/metafates/mangal/filesystem"
"github.com/metafates/mangal/where"
"github.com/samber/mo"
"path/filepath"
Expand All @@ -13,28 +14,33 @@ type cacheData[K comparable, T any] struct {
}

type cacher[K comparable, T any] struct {
internal *cache.Cache[*cacheData[K, T]]
internal *gache.Cache[*cacheData[K, T]]
keyWrapper func(K) K
}

func (c *cacher[K, T]) Get(key K) mo.Option[T] {
data := c.internal.Get()
if data.IsPresent() {
mangas, ok := data.MustGet().Mangas[c.keyWrapper(key)]
if ok {
return mo.Some(mangas)
}
data, expired, err := c.internal.Get()
if err != nil || expired || data == nil {
return mo.None[T]()
}

mangas, ok := data.Mangas[c.keyWrapper(key)]
if ok {
return mo.Some(mangas)
}

return mo.None[T]()
}

func (c *cacher[K, T]) Set(key K, t T) error {
data := c.internal.Get()
if data.IsPresent() {
internal := data.MustGet()
internal.Mangas[c.keyWrapper(key)] = t
return c.internal.Set(internal)
data, expired, err := c.internal.Get()
if err != nil {
return err
}

if !expired && data != nil {
data.Mangas[c.keyWrapper(key)] = t
return c.internal.Set(data)
} else {
internal := &cacheData[K, T]{Mangas: make(map[K]T)}
internal.Mangas[c.keyWrapper(key)] = t
Expand All @@ -43,55 +49,57 @@ func (c *cacher[K, T]) Set(key K, t T) error {
}

func (c *cacher[K, T]) Delete(key K) error {
data := c.internal.Get()
if data.IsPresent() {
internal := data.MustGet()
delete(internal.Mangas, c.keyWrapper(key))
return c.internal.Set(internal)
data, expired, err := c.internal.Get()
if err != nil {
return err
}

if !expired {
delete(data.Mangas, c.keyWrapper(key))
return c.internal.Set(data)
}

return nil
}

var relationCacher = &cacher[string, int]{
internal: cache.New[*cacheData[string, int]](
where.AnilistBinds(),
&cache.Options{
// never expire
ExpireEvery: mo.None[time.Duration](),
internal: gache.New[*cacheData[string, int]](
&gache.Options{
Path: where.AnilistBinds(),
FileSystem: &filesystem.GacheFs{},
},
),
keyWrapper: normalizedName,
}

var searchCacher = &cacher[string, []int]{
internal: cache.New[*cacheData[string, []int]](
filepath.Join(where.Cache(), "anilist_search_cache.json"),
&cache.Options{
// update ids every 10 days, since new manga are not added that often
ExpireEvery: mo.Some(time.Hour * 24 * 10),
internal: gache.New[*cacheData[string, []int]](
&gache.Options{
Path: filepath.Join(where.Cache(), "anilist_search_cache.json"),
Lifetime: time.Hour * 24 * 10,
FileSystem: &filesystem.GacheFs{},
},
),
keyWrapper: normalizedName,
}

var idCacher = &cacher[int, *Manga]{
internal: cache.New[*cacheData[int, *Manga]](
filepath.Join(where.Cache(), "anilist_id_cache.json"),
&cache.Options{
// update manga data every 2 days since it can change often
ExpireEvery: mo.Some(time.Hour * 24 * 2),
internal: gache.New[*cacheData[int, *Manga]](
&gache.Options{
Path: filepath.Join(where.Cache(), "anilist_id_cache.json"),
Lifetime: time.Hour * 24 * 2,
FileSystem: &filesystem.GacheFs{},
},
),
keyWrapper: func(id int) int { return id },
}

var failCacher = &cacher[string, bool]{
internal: cache.New[*cacheData[string, bool]](
filepath.Join(where.Cache(), "anilist_fail_cache.json"),
&cache.Options{
// expire every minute
ExpireEvery: mo.Some(time.Minute),
internal: gache.New[*cacheData[string, bool]](
&gache.Options{
Path: filepath.Join(where.Cache(), "anilist_fail_cache.json"),
Lifetime: time.Minute,
FileSystem: &filesystem.GacheFs{},
},
),
keyWrapper: normalizedName,
Expand Down
45 changes: 0 additions & 45 deletions cache/cache.go

This file was deleted.

13 changes: 0 additions & 13 deletions cache/get.go

This file was deleted.

67 changes: 0 additions & 67 deletions cache/init.go

This file was deleted.

13 changes: 0 additions & 13 deletions cache/options.go

This file was deleted.

33 changes: 0 additions & 33 deletions cache/set.go

This file was deleted.

Loading

0 comments on commit 6e91e01

Please sign in to comment.