Add tracing and optional firechart analysis

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 19e6d21ef7
commit a99d3235a8

@ -2,3 +2,5 @@
test-local test-local
.idea .idea
.env .env
tracing.folded
tracing*.svg

@ -43,6 +43,15 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "ansi_term"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
dependencies = [
"winapi",
]
[[package]] [[package]]
name = "arrayref" name = "arrayref"
version = "0.3.6" version = "0.3.6"
@ -181,7 +190,7 @@ dependencies = [
"arrayref", "arrayref",
"arrayvec 0.7.1", "arrayvec 0.7.1",
"cc", "cc",
"cfg-if", "cfg-if 1.0.0",
"constant_time_eq", "constant_time_eq",
] ]
@ -231,6 +240,12 @@ version = "1.0.70"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa0dc0" checksum = "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa0dc0"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "1.0.0" version = "1.0.0"
@ -257,7 +272,7 @@ version = "2.33.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
dependencies = [ dependencies = [
"ansi_term", "ansi_term 0.11.0",
"atty", "atty",
"bitflags", "bitflags",
"strsim", "strsim",
@ -330,7 +345,7 @@ version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
] ]
[[package]] [[package]]
@ -339,8 +354,8 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"crossbeam-utils", "crossbeam-utils 0.8.5",
] ]
[[package]] [[package]]
@ -349,9 +364,9 @@ version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"crossbeam-epoch", "crossbeam-epoch",
"crossbeam-utils", "crossbeam-utils 0.8.5",
] ]
[[package]] [[package]]
@ -360,8 +375,8 @@ version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd" checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"crossbeam-utils", "crossbeam-utils 0.8.5",
"lazy_static", "lazy_static",
"memoffset", "memoffset",
"scopeguard", "scopeguard",
@ -373,8 +388,19 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b10ddc024425c88c2ad148c1b0fd53f4c6d38db9697c9f1588381212fa657c9" checksum = "9b10ddc024425c88c2ad148c1b0fd53f4c6d38db9697c9f1588381212fa657c9"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"crossbeam-utils", "crossbeam-utils 0.8.5",
]
[[package]]
name = "crossbeam-utils"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
dependencies = [
"autocfg",
"cfg-if 0.1.10",
"lazy_static",
] ]
[[package]] [[package]]
@ -383,7 +409,7 @@ version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"lazy_static", "lazy_static",
] ]
@ -482,6 +508,12 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "futures"
version = "0.1.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678"
[[package]] [[package]]
name = "futures" name = "futures"
version = "0.3.17" version = "0.3.17"
@ -603,7 +635,7 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"libc", "libc",
"wasi", "wasi",
] ]
@ -721,7 +753,7 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "716d3d89f35ac6a34fd0eed635395f4c3b76fa889338a4632e5231a8684216bd" checksum = "716d3d89f35ac6a34fd0eed635395f4c3b76fa889338a4632e5231a8684216bd"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
] ]
[[package]] [[package]]
@ -801,7 +833,16 @@ version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
]
[[package]]
name = "matchers"
version = "0.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1"
dependencies = [
"regex-automata",
] ]
[[package]] [[package]]
@ -823,6 +864,8 @@ dependencies = [
"structopt", "structopt",
"tokio", "tokio",
"toml", "toml",
"tracing-flame",
"tracing-subscriber",
] ]
[[package]] [[package]]
@ -830,7 +873,7 @@ name = "mediarepo-core"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"base64", "base64",
"futures", "futures 0.3.17",
"image", "image",
"multibase", "multibase",
"multihash", "multihash",
@ -866,6 +909,7 @@ dependencies = [
"sea-orm", "sea-orm",
"serde", "serde",
"tokio", "tokio",
"tracing",
"typemap_rev", "typemap_rev",
] ]
@ -878,6 +922,8 @@ dependencies = [
"mediarepo-model", "mediarepo-model",
"serde", "serde",
"tokio", "tokio",
"tracing",
"tracing-futures",
] ]
[[package]] [[package]]
@ -1119,7 +1165,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d9facdb76fec0b73c406f125d44d86fdad818d66fef0531eec9233ca425ff4a" checksum = "8d9facdb76fec0b73c406f125d44d86fdad818d66fef0531eec9233ca425ff4a"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"cfg-if", "cfg-if 1.0.0",
"foreign-types", "foreign-types",
"libc", "libc",
"once_cell", "once_cell",
@ -1162,7 +1208,7 @@ version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"instant", "instant",
"libc", "libc",
"redox_syscall", "redox_syscall",
@ -1176,6 +1222,26 @@ version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
[[package]]
name = "pin-project"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "576bc800220cc65dac09e99e97b08b358cfab6e17078de8dc5fee223bd2d0c08"
dependencies = [
"pin-project-internal",
]
[[package]]
name = "pin-project-internal"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e8fe8163d14ce7f0cdac2e040116f22eac817edabff0be91e8aff7e9accf389"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.2.7" version = "0.2.7"
@ -1378,7 +1444,7 @@ checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e"
dependencies = [ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"crossbeam-deque", "crossbeam-deque",
"crossbeam-utils", "crossbeam-utils 0.8.5",
"lazy_static", "lazy_static",
"num_cpus", "num_cpus",
] ]
@ -1403,6 +1469,15 @@ dependencies = [
"regex-syntax", "regex-syntax",
] ]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
dependencies = [
"regex-syntax",
]
[[package]] [[package]]
name = "regex-syntax" name = "regex-syntax"
version = "0.6.25" version = "0.6.25"
@ -1430,16 +1505,16 @@ dependencies = [
[[package]] [[package]]
name = "rmp-ipc" name = "rmp-ipc"
version = "0.7.0" version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17765aa8bd4d19dd81c53c0707192115f36ec200aea9f4557526932ac1f418e0" checksum = "f68b5ec0f51d53896979bb5364c10c6b0edf753b56570f1f2425b24ea6e85955"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"log",
"rmp-serde", "rmp-serde",
"serde", "serde",
"thiserror", "thiserror",
"tokio", "tokio",
"tracing",
"typemap_rev", "typemap_rev",
] ]
@ -1502,7 +1577,7 @@ dependencies = [
"async-stream", "async-stream",
"async-trait", "async-trait",
"chrono", "chrono",
"futures", "futures 0.3.17",
"futures-util", "futures-util",
"rust_decimal", "rust_decimal",
"sea-orm-macros", "sea-orm-macros",
@ -1637,7 +1712,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa"
dependencies = [ dependencies = [
"block-buffer", "block-buffer",
"cfg-if", "cfg-if 1.0.0",
"cpufeatures", "cpufeatures",
"digest", "digest",
"opaque-debug", "opaque-debug",
@ -1655,6 +1730,15 @@ dependencies = [
"opaque-debug", "opaque-debug",
] ]
[[package]]
name = "sharded-slab"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31"
dependencies = [
"lazy_static",
]
[[package]] [[package]]
name = "slab" name = "slab"
version = "0.4.4" version = "0.4.4"
@ -1703,7 +1787,7 @@ dependencies = [
"crc", "crc",
"crossbeam-channel", "crossbeam-channel",
"crossbeam-queue", "crossbeam-queue",
"crossbeam-utils", "crossbeam-utils 0.8.5",
"either", "either",
"futures-channel", "futures-channel",
"futures-core", "futures-core",
@ -1848,7 +1932,7 @@ version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"libc", "libc",
"rand", "rand",
"redox_syscall", "redox_syscall",
@ -1894,6 +1978,15 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "thread_local"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd"
dependencies = [
"once_cell",
]
[[package]] [[package]]
name = "tiff" name = "tiff"
version = "0.6.1" version = "0.6.1"
@ -1948,6 +2041,16 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "tokio-executor"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb2d1b8f4548dbf5e1f7818512e9c406860678f29c300cdf0ebac72d1a3a1671"
dependencies = [
"crossbeam-utils 0.7.2",
"futures 0.1.31",
]
[[package]] [[package]]
name = "tokio-macros" name = "tokio-macros"
version = "1.4.1" version = "1.4.1"
@ -1989,6 +2092,103 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "tracing"
version = "0.1.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105"
dependencies = [
"cfg-if 1.0.0",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4"
dependencies = [
"lazy_static",
]
[[package]]
name = "tracing-flame"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd520fe41c667b437952383f3a1ec14f1fa45d653f719a77eedd6e6a02d8fa54"
dependencies = [
"lazy_static",
"tracing",
"tracing-subscriber",
]
[[package]]
name = "tracing-futures"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2"
dependencies = [
"pin-project",
"tokio-executor",
"tracing",
]
[[package]]
name = "tracing-log"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6923477a48e41c1951f1999ef8bb5a3023eb723ceadafe78ffb65dc366761e3"
dependencies = [
"lazy_static",
"log",
"tracing-core",
]
[[package]]
name = "tracing-serde"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b"
dependencies = [
"serde",
"tracing-core",
]
[[package]]
name = "tracing-subscriber"
version = "0.2.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71"
dependencies = [
"ansi_term 0.12.1",
"chrono",
"lazy_static",
"matchers",
"regex",
"serde",
"serde_json",
"sharded-slab",
"smallvec",
"thread_local",
"tracing",
"tracing-core",
"tracing-log",
"tracing-serde",
]
[[package]] [[package]]
name = "typemap_rev" name = "typemap_rev"
version = "0.1.5" version = "0.1.5"
@ -2107,7 +2307,7 @@ version = "0.2.78"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"wasm-bindgen-macro", "wasm-bindgen-macro",
] ]

@ -20,6 +20,8 @@ structopt = {version="0.3.23", optional=true}
pretty_env_logger = {version="0.4.0", optional=true} pretty_env_logger = {version="0.4.0", optional=true}
glob = {version="0.3.0", optional=true} glob = {version="0.3.0", optional=true}
log = "0.4.14" log = "0.4.14"
tracing-flame = "0.1.0"
tracing-subscriber = "0.2.3"
[dependencies.mediarepo-core] [dependencies.mediarepo-core]
path = "./mediarepo-core" path = "./mediarepo-core"

@ -1034,16 +1034,16 @@ dependencies = [
[[package]] [[package]]
name = "rmp-ipc" name = "rmp-ipc"
version = "0.7.0" version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17765aa8bd4d19dd81c53c0707192115f36ec200aea9f4557526932ac1f418e0" checksum = "f68b5ec0f51d53896979bb5364c10c6b0edf753b56570f1f2425b24ea6e85955"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"log",
"rmp-serde", "rmp-serde",
"serde", "serde",
"thiserror", "thiserror",
"tokio", "tokio",
"tracing",
"typemap_rev", "typemap_rev",
] ]
@ -1374,6 +1374,38 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "tracing"
version = "0.1.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105"
dependencies = [
"cfg-if",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4"
dependencies = [
"lazy_static",
]
[[package]] [[package]]
name = "typemap_rev" name = "typemap_rev"
version = "0.1.5" version = "0.1.5"

@ -12,7 +12,7 @@ multibase = "0.9.1"
base64 = "0.13.0" base64 = "0.13.0"
toml = "0.5.8" toml = "0.5.8"
serde = "1.0.130" serde = "1.0.130"
rmp-ipc = "0.7.0" rmp-ipc = "0.7.2"
typemap_rev = "0.1.5" typemap_rev = "0.1.5"
image = "0.23.14" image = "0.23.14"
futures = "0.3.17" futures = "0.3.17"

@ -8,7 +8,7 @@ use tokio::fs::OpenOptions;
use tokio::io::{AsyncRead, AsyncReadExt, BufReader}; use tokio::io::{AsyncRead, AsyncReadExt, BufReader};
/// Represents the different sizes of a thumbnail /// Represents the different sizes of a thumbnail
#[derive(Clone, Copy)] #[derive(Clone, Copy, Debug)]
pub enum ThumbnailSize { pub enum ThumbnailSize {
Small, Small,
Medium, Medium,

@ -1267,16 +1267,16 @@ dependencies = [
[[package]] [[package]]
name = "rmp-ipc" name = "rmp-ipc"
version = "0.7.0" version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17765aa8bd4d19dd81c53c0707192115f36ec200aea9f4557526932ac1f418e0" checksum = "f68b5ec0f51d53896979bb5364c10c6b0edf753b56570f1f2425b24ea6e85955"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"log",
"rmp-serde", "rmp-serde",
"serde", "serde",
"thiserror", "thiserror",
"tokio", "tokio",
"tracing",
"typemap_rev", "typemap_rev",
] ]
@ -1765,6 +1765,38 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "tracing"
version = "0.1.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105"
dependencies = [
"cfg-if",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4"
dependencies = [
"lazy_static",
]
[[package]] [[package]]
name = "typemap_rev" name = "typemap_rev"
version = "0.1.5" version = "0.1.5"

@ -778,6 +778,7 @@ dependencies = [
"sea-orm", "sea-orm",
"serde", "serde",
"tokio", "tokio",
"tracing",
"typemap_rev", "typemap_rev",
] ]
@ -1298,16 +1299,16 @@ dependencies = [
[[package]] [[package]]
name = "rmp-ipc" name = "rmp-ipc"
version = "0.7.0" version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17765aa8bd4d19dd81c53c0707192115f36ec200aea9f4557526932ac1f418e0" checksum = "f68b5ec0f51d53896979bb5364c10c6b0edf753b56570f1f2425b24ea6e85955"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"log",
"rmp-serde", "rmp-serde",
"serde", "serde",
"thiserror", "thiserror",
"tokio", "tokio",
"tracing",
"typemap_rev", "typemap_rev",
] ]
@ -1797,6 +1798,38 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "tracing"
version = "0.1.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105"
dependencies = [
"cfg-if",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4"
dependencies = [
"lazy_static",
]
[[package]] [[package]]
name = "typemap_rev" name = "typemap_rev"
version = "0.1.5" version = "0.1.5"

@ -11,6 +11,7 @@ typemap_rev = "0.1.5"
serde = "1.0.130" serde = "1.0.130"
mime_guess = "2.0.3" mime_guess = "2.0.3"
mime = "0.3.16" mime = "0.3.16"
tracing = "0.1.29"
[dependencies.mediarepo-core] [dependencies.mediarepo-core]
path = "../mediarepo-core" path = "../mediarepo-core"

@ -18,6 +18,7 @@ use sea_orm::prelude::*;
use sea_orm::sea_query::{Expr, Query}; use sea_orm::sea_query::{Expr, Query};
use sea_orm::{Condition, DatabaseConnection, Set}; use sea_orm::{Condition, DatabaseConnection, Set};
use sea_orm::{JoinType, QuerySelect}; use sea_orm::{JoinType, QuerySelect};
use std::fmt::Debug;
use tokio::io::BufReader; use tokio::io::BufReader;
#[derive(Clone)] #[derive(Clone)]
@ -28,11 +29,13 @@ pub struct File {
} }
impl File { impl File {
#[tracing::instrument(level = "trace")]
pub(crate) fn new(db: DatabaseConnection, model: file::Model, hash: hash::Model) -> Self { pub(crate) fn new(db: DatabaseConnection, model: file::Model, hash: hash::Model) -> Self {
Self { db, model, hash } Self { db, model, hash }
} }
/// Returns a list of all known stored files /// Returns a list of all known stored files
#[tracing::instrument(level = "debug", skip(db))]
pub async fn all(db: DatabaseConnection) -> RepoResult<Vec<File>> { pub async fn all(db: DatabaseConnection) -> RepoResult<Vec<File>> {
let files: Vec<(file::Model, Option<hash::Model>)> = file::Entity::find() let files: Vec<(file::Model, Option<hash::Model>)> = file::Entity::find()
.find_also_related(hash::Entity) .find_also_related(hash::Entity)
@ -50,6 +53,7 @@ impl File {
} }
/// Fetches the file by id /// Fetches the file by id
#[tracing::instrument(level = "debug", skip(db))]
pub async fn by_id(db: DatabaseConnection, id: i64) -> RepoResult<Option<Self>> { pub async fn by_id(db: DatabaseConnection, id: i64) -> RepoResult<Option<Self>> {
if let Some((model, Some(hash))) = file::Entity::find_by_id(id) if let Some((model, Some(hash))) = file::Entity::find_by_id(id)
.find_also_related(hash::Entity) .find_also_related(hash::Entity)
@ -64,7 +68,8 @@ impl File {
} }
/// Finds the file by hash /// Finds the file by hash
pub async fn by_hash<S: AsRef<str>>( #[tracing::instrument(level = "debug", skip(db))]
pub async fn by_hash<S: AsRef<str> + Debug>(
db: DatabaseConnection, db: DatabaseConnection,
hash: S, hash: S,
) -> RepoResult<Option<Self>> { ) -> RepoResult<Option<Self>> {
@ -81,6 +86,8 @@ impl File {
} }
} }
/// Finds the file by tags
#[tracing::instrument(level = "debug", skip(db))]
pub(crate) async fn find_by_tags( pub(crate) async fn find_by_tags(
db: DatabaseConnection, db: DatabaseConnection,
tag_ids: Vec<i64>, tag_ids: Vec<i64>,
@ -113,6 +120,7 @@ impl File {
} }
/// Adds a file with its hash to the database /// Adds a file with its hash to the database
#[tracing::instrument(level = "debug", skip(db))]
pub(crate) async fn add( pub(crate) async fn add(
db: DatabaseConnection, db: DatabaseConnection,
storage_id: i64, storage_id: i64,
@ -199,11 +207,13 @@ impl File {
} }
/// Returns a list of thumbnails for the file /// Returns a list of thumbnails for the file
#[tracing::instrument(level = "debug", skip(self))]
pub async fn thumbnails(&self) -> RepoResult<Vec<Thumbnail>> { pub async fn thumbnails(&self) -> RepoResult<Vec<Thumbnail>> {
Thumbnail::for_file_id(self.db.clone(), self.model.id).await Thumbnail::for_file_id(self.db.clone(), self.model.id).await
} }
/// Returns the list of tags of the file /// Returns the list of tags of the file
#[tracing::instrument(level = "debug", skip(self))]
pub async fn tags(&self) -> RepoResult<Vec<Tag>> { pub async fn tags(&self) -> RepoResult<Vec<Tag>> {
let tags: Vec<(tag::Model, Option<namespace::Model>)> = tag::Entity::find() let tags: Vec<(tag::Model, Option<namespace::Model>)> = tag::Entity::find()
.find_also_related(namespace::Entity) .find_also_related(namespace::Entity)
@ -221,7 +231,8 @@ impl File {
} }
/// Changes the name of the file /// Changes the name of the file
pub async fn set_name<S: ToString>(&mut self, name: S) -> RepoResult<()> { #[tracing::instrument(level = "debug", skip(self))]
pub async fn set_name<S: ToString + Debug>(&mut self, name: S) -> RepoResult<()> {
let mut active_file = self.get_active_model(); let mut active_file = self.get_active_model();
active_file.name = Set(Some(name.to_string())); active_file.name = Set(Some(name.to_string()));
let active_file = active_file.update(&self.db).await?; let active_file = active_file.update(&self.db).await?;
@ -231,7 +242,8 @@ impl File {
} }
/// Changes the comment of the file /// Changes the comment of the file
pub async fn set_comment<S: ToString>(&mut self, comment: S) -> RepoResult<()> { #[tracing::instrument(level = "debug", skip(self))]
pub async fn set_comment<S: ToString + Debug>(&mut self, comment: S) -> RepoResult<()> {
let mut active_file = self.get_active_model(); let mut active_file = self.get_active_model();
active_file.comment = Set(Some(comment.to_string())); active_file.comment = Set(Some(comment.to_string()));
let active_file = active_file.update(&self.db).await?; let active_file = active_file.update(&self.db).await?;
@ -241,6 +253,7 @@ impl File {
} }
/// Changes the type of the file /// Changes the type of the file
#[tracing::instrument(level = "debug", skip(self))]
pub async fn set_file_type(&mut self, file_type: FileType) -> RepoResult<()> { pub async fn set_file_type(&mut self, file_type: FileType) -> RepoResult<()> {
let mut active_file = self.get_active_model(); let mut active_file = self.get_active_model();
active_file.file_type = Set(file_type as u32); active_file.file_type = Set(file_type as u32);
@ -251,6 +264,7 @@ impl File {
} }
/// Adds a single tag to the file /// Adds a single tag to the file
#[tracing::instrument(level = "debug", skip(self))]
pub async fn add_tag(&mut self, tag_id: i64) -> RepoResult<()> { pub async fn add_tag(&mut self, tag_id: i64) -> RepoResult<()> {
let hash_id = self.hash.id; let hash_id = self.hash.id;
let active_model = hash_tag::ActiveModel { let active_model = hash_tag::ActiveModel {
@ -262,6 +276,7 @@ impl File {
} }
/// Adds multiple tags to the file at once /// Adds multiple tags to the file at once
#[tracing::instrument(level = "debug", skip(self))]
pub async fn add_tags(&self, tag_ids: Vec<i64>) -> RepoResult<()> { pub async fn add_tags(&self, tag_ids: Vec<i64>) -> RepoResult<()> {
let hash_id = self.hash.id; let hash_id = self.hash.id;
let models: Vec<hash_tag::ActiveModel> = tag_ids let models: Vec<hash_tag::ActiveModel> = tag_ids
@ -277,6 +292,7 @@ impl File {
} }
/// Returns the reader for the file /// Returns the reader for the file
#[tracing::instrument(level = "debug", skip(self))]
pub async fn get_reader(&self) -> RepoResult<BufReader<tokio::fs::File>> { pub async fn get_reader(&self) -> RepoResult<BufReader<tokio::fs::File>> {
let storage = self.storage().await?; let storage = self.storage().await?;
@ -284,6 +300,7 @@ impl File {
} }
/// Creates a thumbnail for the file /// Creates a thumbnail for the file
#[tracing::instrument(level = "debug", skip(self))]
pub async fn create_thumbnail( pub async fn create_thumbnail(
&self, &self,
size: ThumbnailSize, size: ThumbnailSize,
@ -297,6 +314,7 @@ impl File {
} }
/// Creates a thumbnail for an image /// Creates a thumbnail for an image
#[tracing::instrument(level = "debug", skip(self))]
async fn create_image_thumbnail( async fn create_image_thumbnail(
&self, &self,
size: ThumbnailSize, size: ThumbnailSize,

@ -6,6 +6,7 @@ use mediarepo_database::entities::hash;
use mediarepo_database::entities::thumbnail; use mediarepo_database::entities::thumbnail;
use sea_orm::prelude::*; use sea_orm::prelude::*;
use sea_orm::{DatabaseConnection, Set}; use sea_orm::{DatabaseConnection, Set};
use std::fmt::Debug;
pub struct Hash { pub struct Hash {
db: DatabaseConnection, db: DatabaseConnection,
@ -13,11 +14,13 @@ pub struct Hash {
} }
impl Hash { impl Hash {
#[tracing::instrument(level = "trace")]
pub(crate) fn new(db: DatabaseConnection, model: hash::Model) -> Self { pub(crate) fn new(db: DatabaseConnection, model: hash::Model) -> Self {
Self { db, model } Self { db, model }
} }
/// Searches for the hash by id /// Searches for the hash by id
#[tracing::instrument(level = "debug", skip(db))]
pub async fn by_id(db: DatabaseConnection, id: i64) -> RepoResult<Option<Self>> { pub async fn by_id(db: DatabaseConnection, id: i64) -> RepoResult<Option<Self>> {
let hash = hash::Entity::find_by_id(id) let hash = hash::Entity::find_by_id(id)
.one(&db) .one(&db)
@ -28,7 +31,8 @@ impl Hash {
} }
/// Returns the hash by value /// Returns the hash by value
pub async fn by_value<S: AsRef<str>>( #[tracing::instrument(level = "debug", skip(db))]
pub async fn by_value<S: AsRef<str> + Debug>(
db: DatabaseConnection, db: DatabaseConnection,
value: S, value: S,
) -> RepoResult<Option<Self>> { ) -> RepoResult<Option<Self>> {
@ -42,6 +46,7 @@ impl Hash {
} }
/// Adds a new hash to the database /// Adds a new hash to the database
#[tracing::instrument(level = "debug", skip(db))]
pub async fn add(db: DatabaseConnection, value: String) -> RepoResult<Self> { pub async fn add(db: DatabaseConnection, value: String) -> RepoResult<Self> {
let active_model = hash::ActiveModel { let active_model = hash::ActiveModel {
value: Set(value), value: Set(value),
@ -64,6 +69,7 @@ impl Hash {
} }
/// Returns the file associated with the hash /// Returns the file associated with the hash
#[tracing::instrument(level = "debug", skip(self))]
pub async fn file(&self) -> RepoResult<Option<File>> { pub async fn file(&self) -> RepoResult<Option<File>> {
let file = self let file = self
.model .model
@ -76,6 +82,7 @@ impl Hash {
} }
/// Returns the the thumbnail associated with the hash /// Returns the the thumbnail associated with the hash
#[tracing::instrument(level = "debug", skip(self))]
pub async fn thumbnail(&self) -> RepoResult<Option<Thumbnail>> { pub async fn thumbnail(&self) -> RepoResult<Option<Thumbnail>> {
let thumbnail = self let thumbnail = self
.model .model

@ -2,6 +2,7 @@ use mediarepo_core::error::RepoResult;
use mediarepo_database::entities::namespace; use mediarepo_database::entities::namespace;
use sea_orm::prelude::*; use sea_orm::prelude::*;
use sea_orm::{DatabaseConnection, Set}; use sea_orm::{DatabaseConnection, Set};
use std::fmt::Debug;
#[derive(Clone)] #[derive(Clone)]
pub struct Namespace { pub struct Namespace {
@ -10,11 +11,13 @@ pub struct Namespace {
} }
impl Namespace { impl Namespace {
#[tracing::instrument(level = "trace")]
pub(crate) fn new(db: DatabaseConnection, model: namespace::Model) -> Self { pub(crate) fn new(db: DatabaseConnection, model: namespace::Model) -> Self {
Self { db, model } Self { db, model }
} }
/// Retrieves the namespace by id /// Retrieves the namespace by id
#[tracing::instrument(level = "debug", skip(db))]
pub async fn by_id(db: DatabaseConnection, id: i64) -> RepoResult<Option<Self>> { pub async fn by_id(db: DatabaseConnection, id: i64) -> RepoResult<Option<Self>> {
let namespace = namespace::Entity::find_by_id(id) let namespace = namespace::Entity::find_by_id(id)
.one(&db) .one(&db)
@ -25,7 +28,8 @@ impl Namespace {
} }
/// Retrieves a namespace by its name /// Retrieves a namespace by its name
pub async fn by_name<S: AsRef<str>>( #[tracing::instrument(level = "debug", skip(db))]
pub async fn by_name<S: AsRef<str> + Debug>(
db: DatabaseConnection, db: DatabaseConnection,
name: S, name: S,
) -> RepoResult<Option<Self>> { ) -> RepoResult<Option<Self>> {
@ -39,7 +43,8 @@ impl Namespace {
} }
/// Adds a namespace to the database /// Adds a namespace to the database
pub async fn add<S: ToString>(db: DatabaseConnection, name: S) -> RepoResult<Self> { #[tracing::instrument(level = "debug", skip(db))]
pub async fn add<S: ToString + Debug>(db: DatabaseConnection, name: S) -> RepoResult<Self> {
let active_model = namespace::ActiveModel { let active_model = namespace::ActiveModel {
name: Set(name.to_string()), name: Set(name.to_string()),
..Default::default() ..Default::default()

@ -9,6 +9,7 @@ use mediarepo_core::image_processing::ThumbnailSize;
use mediarepo_core::utils::parse_namespace_and_tag; use mediarepo_core::utils::parse_namespace_and_tag;
use mediarepo_database::get_database; use mediarepo_database::get_database;
use sea_orm::DatabaseConnection; use sea_orm::DatabaseConnection;
use std::fmt::Debug;
use std::io::Cursor; use std::io::Cursor;
use std::path::PathBuf; use std::path::PathBuf;
use tokio::fs::OpenOptions; use tokio::fs::OpenOptions;
@ -31,35 +32,44 @@ impl Repo {
} }
/// Connects to the database with the given uri /// Connects to the database with the given uri
pub async fn connect<S: AsRef<str>>(uri: S) -> RepoResult<Self> { #[tracing::instrument(level = "debug")]
pub async fn connect<S: AsRef<str> + Debug>(uri: S) -> RepoResult<Self> {
let db = get_database(uri).await?; let db = get_database(uri).await?;
Ok(Self::new(db)) Ok(Self::new(db))
} }
/// Returns all available storages /// Returns all available storages
#[tracing::instrument(level = "debug", skip(self))]
pub async fn storages(&self) -> RepoResult<Vec<Storage>> { pub async fn storages(&self) -> RepoResult<Vec<Storage>> {
Storage::all(self.db.clone()).await Storage::all(self.db.clone()).await
} }
/// Returns a storage by path /// Returns a storage by path
pub async fn storage_by_path<S: ToString>(&self, path: S) -> RepoResult<Option<Storage>> { #[tracing::instrument(level = "debug", skip(self))]
pub async fn storage_by_path<S: ToString + Debug>(
&self,
path: S,
) -> RepoResult<Option<Storage>> {
Storage::by_path(self.db.clone(), path).await Storage::by_path(self.db.clone(), path).await
} }
/// Sets the main storage /// Sets the main storage
pub async fn set_main_storage<S: ToString>(&mut self, path: S) -> RepoResult<()> { #[tracing::instrument(level = "debug", skip(self))]
pub async fn set_main_storage<S: ToString + Debug>(&mut self, path: S) -> RepoResult<()> {
self.main_storage = Storage::by_path(self.db.clone(), path).await?; self.main_storage = Storage::by_path(self.db.clone(), path).await?;
Ok(()) Ok(())
} }
/// Sets the default thumbnail storage /// Sets the default thumbnail storage
pub async fn set_thumbnail_storage<S: ToString>(&mut self, path: S) -> RepoResult<()> { #[tracing::instrument(level = "debug", skip(self))]
pub async fn set_thumbnail_storage<S: ToString + Debug>(&mut self, path: S) -> RepoResult<()> {
self.thumbnail_storage = Storage::by_path(self.db.clone(), path).await?; self.thumbnail_storage = Storage::by_path(self.db.clone(), path).await?;
Ok(()) Ok(())
} }
/// Adds a storage to the repository /// Adds a storage to the repository
pub async fn add_storage<S1: ToString, S2: ToString>( #[tracing::instrument(level = "debug", skip(self))]
pub async fn add_storage<S1: ToString + Debug, S2: ToString + Debug>(
&self, &self,
name: S1, name: S1,
path: S2, path: S2,
@ -68,21 +78,25 @@ impl Repo {
} }
/// Returns a file by its mapped hash /// Returns a file by its mapped hash
pub async fn file_by_hash<S: AsRef<str>>(&self, hash: S) -> RepoResult<Option<File>> { #[tracing::instrument(level = "debug", skip(self))]
pub async fn file_by_hash<S: AsRef<str> + Debug>(&self, hash: S) -> RepoResult<Option<File>> {
File::by_hash(self.db.clone(), hash).await File::by_hash(self.db.clone(), hash).await
} }
/// Returns a file by id /// Returns a file by id
#[tracing::instrument(level = "debug", skip(self))]
pub async fn file_by_id(&self, id: i64) -> RepoResult<Option<File>> { pub async fn file_by_id(&self, id: i64) -> RepoResult<Option<File>> {
File::by_id(self.db.clone(), id).await File::by_id(self.db.clone(), id).await
} }
/// Returns a list of all stored files /// Returns a list of all stored files
#[tracing::instrument(level = "debug", skip(self))]
pub async fn files(&self) -> RepoResult<Vec<File>> { pub async fn files(&self) -> RepoResult<Vec<File>> {
File::all(self.db.clone()).await File::all(self.db.clone()).await
} }
/// Finds all files by a list of tags /// Finds all files by a list of tags
#[tracing::instrument(level = "debug", skip(self))]
pub async fn find_files_by_tags(&self, tags: Vec<String>) -> RepoResult<Vec<File>> { pub async fn find_files_by_tags(&self, tags: Vec<String>) -> RepoResult<Vec<File>> {
let tags = self.find_all_tags(tags).await?; let tags = self.find_all_tags(tags).await?;
let tag_ids = tags.into_iter().map(|tag| tag.id()).collect(); let tag_ids = tags.into_iter().map(|tag| tag.id()).collect();
@ -91,6 +105,7 @@ impl Repo {
} }
/// Adds a file to the database by its readable path in the file system /// Adds a file to the database by its readable path in the file system
#[tracing::instrument(level = "debug", skip(self))]
pub async fn add_file_by_path(&self, path: PathBuf) -> RepoResult<File> { pub async fn add_file_by_path(&self, path: PathBuf) -> RepoResult<File> {
let mime_match = mime_guess::from_path(&path).first(); let mime_match = mime_guess::from_path(&path).first();
@ -115,11 +130,16 @@ impl Repo {
} }
/// Returns a thumbnail by its hash /// Returns a thumbnail by its hash
pub async fn thumbnail_by_hash<S: AsRef<str>>(&self, hash: S) -> RepoResult<Option<Thumbnail>> { #[tracing::instrument(level = "debug", skip(self))]
pub async fn thumbnail_by_hash<S: AsRef<str> + Debug>(
&self,
hash: S,
) -> RepoResult<Option<Thumbnail>> {
Thumbnail::by_hash(self.db.clone(), hash).await Thumbnail::by_hash(self.db.clone(), hash).await
} }
/// Creates thumbnails of all sizes for a file /// Creates thumbnails of all sizes for a file
#[tracing::instrument(level = "debug", skip(self, file))]
pub async fn create_thumbnails_for_file(&self, file: File) -> RepoResult<()> { pub async fn create_thumbnails_for_file(&self, file: File) -> RepoResult<()> {
let thumb_storage = self.get_thumbnail_storage()?; let thumb_storage = self.get_thumbnail_storage()?;
for size in [ for size in [
@ -145,11 +165,13 @@ impl Repo {
} }
/// Returns all tags stored in the database /// Returns all tags stored in the database
#[tracing::instrument(level = "debug", skip(self))]
pub async fn tags(&self) -> RepoResult<Vec<Tag>> { pub async fn tags(&self) -> RepoResult<Vec<Tag>> {
Tag::all(self.db.clone()).await Tag::all(self.db.clone()).await
} }
/// Finds all tags by name /// Finds all tags by name
#[tracing::instrument(level = "debug", skip(self))]
pub async fn find_all_tags(&self, tags: Vec<String>) -> RepoResult<Vec<Tag>> { pub async fn find_all_tags(&self, tags: Vec<String>) -> RepoResult<Vec<Tag>> {
let tags: Vec<(Option<String>, String)> = let tags: Vec<(Option<String>, String)> =
tags.into_iter().map(parse_namespace_and_tag).collect(); tags.into_iter().map(parse_namespace_and_tag).collect();
@ -157,7 +179,8 @@ impl Repo {
} }
/// Adds or finds a tag /// Adds or finds a tag
pub async fn add_or_find_tag<S: ToString>(&self, tag: S) -> RepoResult<Tag> { #[tracing::instrument(level = "debug", skip(self))]
pub async fn add_or_find_tag<S: ToString + Debug>(&self, tag: S) -> RepoResult<Tag> {
let (namespace, name) = parse_namespace_and_tag(tag.to_string()); let (namespace, name) = parse_namespace_and_tag(tag.to_string());
if let Some(namespace) = namespace { if let Some(namespace) = namespace {
self.add_or_find_namespaced_tag(name, namespace).await self.add_or_find_namespaced_tag(name, namespace).await
@ -167,6 +190,7 @@ impl Repo {
} }
/// Adds or finds an unnamespaced tag /// Adds or finds an unnamespaced tag
#[tracing::instrument(level = "debug", skip(self))]
pub async fn add_or_find_unnamespaced_tag(&self, name: String) -> RepoResult<Tag> { pub async fn add_or_find_unnamespaced_tag(&self, name: String) -> RepoResult<Tag> {
if let Some(tag) = Tag::by_name(self.db.clone(), &name, None).await? { if let Some(tag) = Tag::by_name(self.db.clone(), &name, None).await? {
Ok(tag) Ok(tag)
@ -176,11 +200,13 @@ impl Repo {
} }
/// Adds an unnamespaced tag /// Adds an unnamespaced tag
#[tracing::instrument(level = "debug", skip(self))]
async fn add_unnamespaced_tag(&self, name: String) -> RepoResult<Tag> { async fn add_unnamespaced_tag(&self, name: String) -> RepoResult<Tag> {
Tag::add(self.db.clone(), name, None).await Tag::add(self.db.clone(), name, None).await
} }
/// Adds or finds a namespaced tag /// Adds or finds a namespaced tag
#[tracing::instrument(level = "debug", skip(self))]
pub async fn add_or_find_namespaced_tag( pub async fn add_or_find_namespaced_tag(
&self, &self,
name: String, name: String,
@ -194,6 +220,7 @@ impl Repo {
} }
/// Adds a namespaced tag /// Adds a namespaced tag
#[tracing::instrument(level = "debug", skip(self))]
async fn add_namespaced_tag(&self, name: String, namespace: String) -> RepoResult<Tag> { async fn add_namespaced_tag(&self, name: String, namespace: String) -> RepoResult<Tag> {
let namespace = let namespace =
if let Some(namespace) = Namespace::by_name(self.db.clone(), &namespace).await? { if let Some(namespace) = Namespace::by_name(self.db.clone(), &namespace).await? {
@ -204,6 +231,7 @@ impl Repo {
Tag::add(self.db.clone(), name, Some(namespace.id())).await Tag::add(self.db.clone(), name, Some(namespace.id())).await
} }
#[tracing::instrument(level = "trace", skip(self))]
fn get_main_storage(&self) -> RepoResult<&Storage> { fn get_main_storage(&self) -> RepoResult<&Storage> {
if let Some(storage) = &self.main_storage { if let Some(storage) = &self.main_storage {
Ok(storage) Ok(storage)
@ -212,6 +240,7 @@ impl Repo {
} }
} }
#[tracing::instrument(level = "trace", skip(self))]
fn get_thumbnail_storage(&self) -> RepoResult<&Storage> { fn get_thumbnail_storage(&self) -> RepoResult<&Storage> {
if let Some(storage) = &self.thumbnail_storage { if let Some(storage) = &self.thumbnail_storage {
Ok(storage) Ok(storage)

@ -6,6 +6,7 @@ use mediarepo_database::entities::storage::ActiveModel as ActiveStorage;
use mediarepo_database::entities::storage::Model as StorageModel; use mediarepo_database::entities::storage::Model as StorageModel;
use sea_orm::prelude::*; use sea_orm::prelude::*;
use sea_orm::{DatabaseConnection, Set, Unset}; use sea_orm::{DatabaseConnection, Set, Unset};
use std::fmt::Debug;
use std::path::PathBuf; use std::path::PathBuf;
use tokio::fs; use tokio::fs;
use tokio::io::{AsyncRead, BufReader}; use tokio::io::{AsyncRead, BufReader};
@ -18,6 +19,7 @@ pub struct Storage {
} }
impl Storage { impl Storage {
#[tracing::instrument(level = "trace")]
fn new(db: DatabaseConnection, model: StorageModel) -> Self { fn new(db: DatabaseConnection, model: StorageModel) -> Self {
let path = PathBuf::from(&model.path); let path = PathBuf::from(&model.path);
Self { Self {
@ -28,6 +30,7 @@ impl Storage {
} }
/// Returns all available storages /// Returns all available storages
#[tracing::instrument(level = "debug", skip(db))]
pub async fn all(db: DatabaseConnection) -> RepoResult<Vec<Self>> { pub async fn all(db: DatabaseConnection) -> RepoResult<Vec<Self>> {
let storages: Vec<storage::Model> = storage::Entity::find().all(&db).await?; let storages: Vec<storage::Model> = storage::Entity::find().all(&db).await?;
let storages = storages let storages = storages
@ -39,6 +42,7 @@ impl Storage {
} }
/// Returns the storage by id /// Returns the storage by id
#[tracing::instrument(level = "debug", skip(db))]
pub async fn by_id(db: DatabaseConnection, id: i64) -> RepoResult<Option<Self>> { pub async fn by_id(db: DatabaseConnection, id: i64) -> RepoResult<Option<Self>> {
if let Some(model) = storage::Entity::find_by_id(id).one(&db).await? { if let Some(model) = storage::Entity::find_by_id(id).one(&db).await? {
let storage = Self::new(db, model); let storage = Self::new(db, model);
@ -49,7 +53,11 @@ impl Storage {
} }
/// Returns the storage by path /// Returns the storage by path
pub async fn by_path<S: ToString>(db: DatabaseConnection, path: S) -> RepoResult<Option<Self>> { #[tracing::instrument(level = "debug", skip(db))]
pub async fn by_path<S: ToString + Debug>(
db: DatabaseConnection,
path: S,
) -> RepoResult<Option<Self>> {
if let Some(model) = storage::Entity::find() if let Some(model) = storage::Entity::find()
.filter(storage::Column::Path.eq(path.to_string())) .filter(storage::Column::Path.eq(path.to_string()))
.one(&db) .one(&db)
@ -64,7 +72,8 @@ impl Storage {
/// Creates a new active storage and also creates the associated directory /// Creates a new active storage and also creates the associated directory
/// if it doesn't exist yet. /// if it doesn't exist yet.
pub async fn create<S1: ToString, S2: ToString>( #[tracing::instrument(level = "debug", skip(db))]
pub async fn create<S1: ToString + Debug, S2: ToString + Debug>(
db: DatabaseConnection, db: DatabaseConnection,
name: S1, name: S1,
path: S2, path: S2,
@ -106,7 +115,8 @@ impl Storage {
} }
/// Sets a new name for the storage /// Sets a new name for the storage
pub async fn set_name<S: ToString>(&self, name: S) -> RepoResult<()> { #[tracing::instrument(level = "debug", skip(self))]
pub async fn set_name<S: ToString + Debug>(&self, name: S) -> RepoResult<()> {
let mut active_storage: ActiveStorage = self.get_active_model(); let mut active_storage: ActiveStorage = self.get_active_model();
active_storage.name = Set(name.to_string()); active_storage.name = Set(name.to_string());
active_storage.update(&self.db).await?; active_storage.update(&self.db).await?;
@ -116,7 +126,8 @@ impl Storage {
/// Sets a new path for the storage. This will only update the database record /// Sets a new path for the storage. This will only update the database record
/// so if the physical part of the storage is already created it needs to be migrated first /// so if the physical part of the storage is already created it needs to be migrated first
pub async fn set_path<S: ToString>(&mut self, path: S) -> RepoResult<()> { #[tracing::instrument(level = "debug", skip(self))]
pub async fn set_path<S: ToString + Debug>(&mut self, path: S) -> RepoResult<()> {
let mut active_storage: ActiveStorage = self.get_active_model(); let mut active_storage: ActiveStorage = self.get_active_model();
active_storage.path = Set(path.to_string()); active_storage.path = Set(path.to_string());
let storage: ActiveStorage = active_storage.update(&self.db).await?; let storage: ActiveStorage = active_storage.update(&self.db).await?;
@ -133,6 +144,7 @@ impl Storage {
} }
/// Adds a thumbnail /// Adds a thumbnail
#[tracing::instrument(level = "debug", skip(self, reader))]
pub async fn store_entry<R: AsyncRead + Unpin>(&self, reader: R) -> RepoResult<Hash> { pub async fn store_entry<R: AsyncRead + Unpin>(&self, reader: R) -> RepoResult<Hash> {
let hash = self.store.add_file(reader, None).await?; let hash = self.store.add_file(reader, None).await?;
if let Some(hash) = Hash::by_value(self.db.clone(), &hash).await? { if let Some(hash) = Hash::by_value(self.db.clone(), &hash).await? {
@ -143,7 +155,8 @@ impl Storage {
} }
/// Returns the buf reader to the given hash /// Returns the buf reader to the given hash
pub async fn get_file_reader<S: ToString>( #[tracing::instrument(level = "debug", skip(self))]
pub async fn get_file_reader<S: ToString + Debug>(
&self, &self,
hash: S, hash: S,
) -> RepoResult<BufReader<tokio::fs::File>> { ) -> RepoResult<BufReader<tokio::fs::File>> {

@ -5,6 +5,7 @@ use mediarepo_database::entities::tag;
use sea_orm::prelude::*; use sea_orm::prelude::*;
use sea_orm::sea_query::Expr; use sea_orm::sea_query::Expr;
use sea_orm::{Condition, DatabaseConnection, Set}; use sea_orm::{Condition, DatabaseConnection, Set};
use std::fmt::Debug;
#[derive(Clone)] #[derive(Clone)]
pub struct Tag { pub struct Tag {
@ -14,6 +15,7 @@ pub struct Tag {
} }
impl Tag { impl Tag {
#[tracing::instrument(level = "trace")]
pub(crate) fn new( pub(crate) fn new(
db: DatabaseConnection, db: DatabaseConnection,
model: tag::Model, model: tag::Model,
@ -27,6 +29,7 @@ impl Tag {
} }
/// Returns all tags stored in the database /// Returns all tags stored in the database
#[tracing::instrument(level = "debug", skip(db))]
pub async fn all(db: DatabaseConnection) -> RepoResult<Vec<Self>> { pub async fn all(db: DatabaseConnection) -> RepoResult<Vec<Self>> {
let tags: Vec<Self> = tag::Entity::find() let tags: Vec<Self> = tag::Entity::find()
.inner_join(namespace::Entity) .inner_join(namespace::Entity)
@ -41,6 +44,7 @@ impl Tag {
} }
/// Returns the tag by id /// Returns the tag by id
#[tracing::instrument(level = "debug", skip(db))]
pub async fn by_id(db: DatabaseConnection, id: i64) -> RepoResult<Option<Self>> { pub async fn by_id(db: DatabaseConnection, id: i64) -> RepoResult<Option<Self>> {
let tag = tag::Entity::find_by_id(id) let tag = tag::Entity::find_by_id(id)
.find_also_related(namespace::Entity) .find_also_related(namespace::Entity)
@ -52,7 +56,8 @@ impl Tag {
} }
/// Returns one tag by name and namespace /// Returns one tag by name and namespace
pub async fn by_name<S1: ToString>( #[tracing::instrument(level = "debug", skip(db))]
pub async fn by_name<S1: ToString + Debug>(
db: DatabaseConnection, db: DatabaseConnection,
name: S1, name: S1,
namespace: Option<String>, namespace: Option<String>,
@ -63,6 +68,7 @@ impl Tag {
} }
/// Retrieves the namespaced tags by name and namespace /// Retrieves the namespaced tags by name and namespace
#[tracing::instrument(level = "debug", skip(db))]
pub async fn all_by_name( pub async fn all_by_name(
db: DatabaseConnection, db: DatabaseConnection,
namespaces_with_names: Vec<(Option<String>, String)>, namespaces_with_names: Vec<(Option<String>, String)>,
@ -93,7 +99,8 @@ impl Tag {
} }
/// Adds a new tag to the database /// Adds a new tag to the database
pub async fn add<S: ToString>( #[tracing::instrument(level = "debug", skip(db))]
pub async fn add<S: ToString + Debug>(
db: DatabaseConnection, db: DatabaseConnection,
name: S, name: S,
namespace_id: Option<i64>, namespace_id: Option<i64>,

@ -4,6 +4,7 @@ use mediarepo_database::entities::hash;
use mediarepo_database::entities::thumbnail; use mediarepo_database::entities::thumbnail;
use sea_orm::prelude::*; use sea_orm::prelude::*;
use sea_orm::{DatabaseConnection, Set}; use sea_orm::{DatabaseConnection, Set};
use std::fmt::Debug;
use tokio::fs::File; use tokio::fs::File;
use tokio::io::BufReader; use tokio::io::BufReader;
@ -14,11 +15,13 @@ pub struct Thumbnail {
} }
impl Thumbnail { impl Thumbnail {
#[tracing::instrument(level = "trace")]
pub(crate) fn new(db: DatabaseConnection, model: thumbnail::Model, hash: hash::Model) -> Self { pub(crate) fn new(db: DatabaseConnection, model: thumbnail::Model, hash: hash::Model) -> Self {
Self { db, model, hash } Self { db, model, hash }
} }
/// Returns the thumbnail by id /// Returns the thumbnail by id
#[tracing::instrument(level = "debug", skip(db))]
pub async fn by_id(db: DatabaseConnection, id: i64) -> RepoResult<Option<Self>> { pub async fn by_id(db: DatabaseConnection, id: i64) -> RepoResult<Option<Self>> {
let model: Option<(thumbnail::Model, Option<hash::Model>)> = let model: Option<(thumbnail::Model, Option<hash::Model>)> =
thumbnail::Entity::find_by_id(id) thumbnail::Entity::find_by_id(id)
@ -34,7 +37,8 @@ impl Thumbnail {
} }
/// Returns a thumbnail by hash /// Returns a thumbnail by hash
pub async fn by_hash<S: AsRef<str>>( #[tracing::instrument(level = "debug", skip(db))]
pub async fn by_hash<S: AsRef<str> + Debug>(
db: DatabaseConnection, db: DatabaseConnection,
hash: S, hash: S,
) -> RepoResult<Option<Self>> { ) -> RepoResult<Option<Self>> {
@ -51,6 +55,7 @@ impl Thumbnail {
} }
/// Inserts a thumbnail into the database /// Inserts a thumbnail into the database
#[tracing::instrument(level = "debug", skip(db))]
pub async fn add( pub async fn add(
db: DatabaseConnection, db: DatabaseConnection,
hash_id: i64, hash_id: i64,
@ -78,6 +83,7 @@ impl Thumbnail {
} }
/// Returns all thumbnails for a given file /// Returns all thumbnails for a given file
#[tracing::instrument(level = "debug", skip(db))]
pub async fn for_file_id(db: DatabaseConnection, file_id: i64) -> RepoResult<Vec<Self>> { pub async fn for_file_id(db: DatabaseConnection, file_id: i64) -> RepoResult<Vec<Self>> {
let thumb_models: Vec<(thumbnail::Model, Option<hash::Model>)> = thumbnail::Entity::find() let thumb_models: Vec<(thumbnail::Model, Option<hash::Model>)> = thumbnail::Entity::find()
.filter(thumbnail::Column::FileId.eq(file_id)) .filter(thumbnail::Column::FileId.eq(file_id))
@ -112,6 +118,7 @@ impl Thumbnail {
} }
/// Returns the storage for the thumbnail /// Returns the storage for the thumbnail
#[tracing::instrument(level = "debug", skip(self))]
pub async fn storage(&self) -> RepoResult<Storage> { pub async fn storage(&self) -> RepoResult<Storage> {
let storage = Storage::by_id(self.db.clone(), self.model.storage_id) let storage = Storage::by_id(self.db.clone(), self.model.storage_id)
.await? .await?
@ -121,6 +128,7 @@ impl Thumbnail {
} }
/// Returns the reader of the thumbnail file /// Returns the reader of the thumbnail file
#[tracing::instrument(level = "debug", skip(self))]
pub async fn get_reader(&self) -> RepoResult<BufReader<File>> { pub async fn get_reader(&self) -> RepoResult<BufReader<File>> {
let storage = self.storage().await?; let storage = self.storage().await?;
storage.get_file_reader(self.hash()).await storage.get_file_reader(self.hash()).await

@ -152,7 +152,7 @@ dependencies = [
"arrayref", "arrayref",
"arrayvec 0.7.1", "arrayvec 0.7.1",
"cc", "cc",
"cfg-if", "cfg-if 1.0.0",
"constant_time_eq", "constant_time_eq",
] ]
@ -202,6 +202,12 @@ version = "1.0.71"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd" checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "1.0.0" version = "1.0.0"
@ -286,7 +292,7 @@ version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
] ]
[[package]] [[package]]
@ -295,8 +301,8 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"crossbeam-utils", "crossbeam-utils 0.8.5",
] ]
[[package]] [[package]]
@ -305,9 +311,9 @@ version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"crossbeam-epoch", "crossbeam-epoch",
"crossbeam-utils", "crossbeam-utils 0.8.5",
] ]
[[package]] [[package]]
@ -316,8 +322,8 @@ version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd" checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"crossbeam-utils", "crossbeam-utils 0.8.5",
"lazy_static", "lazy_static",
"memoffset", "memoffset",
"scopeguard", "scopeguard",
@ -329,8 +335,19 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b10ddc024425c88c2ad148c1b0fd53f4c6d38db9697c9f1588381212fa657c9" checksum = "9b10ddc024425c88c2ad148c1b0fd53f4c6d38db9697c9f1588381212fa657c9"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"crossbeam-utils", "crossbeam-utils 0.8.5",
]
[[package]]
name = "crossbeam-utils"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
dependencies = [
"autocfg",
"cfg-if 0.1.10",
"lazy_static",
] ]
[[package]] [[package]]
@ -339,7 +356,7 @@ version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"lazy_static", "lazy_static",
] ]
@ -425,6 +442,12 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "futures"
version = "0.1.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678"
[[package]] [[package]]
name = "futures" name = "futures"
version = "0.3.17" version = "0.3.17"
@ -546,7 +569,7 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"libc", "libc",
"wasi", "wasi",
] ]
@ -649,7 +672,7 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "716d3d89f35ac6a34fd0eed635395f4c3b76fa889338a4632e5231a8684216bd" checksum = "716d3d89f35ac6a34fd0eed635395f4c3b76fa889338a4632e5231a8684216bd"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
] ]
[[package]] [[package]]
@ -729,7 +752,7 @@ version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
] ]
[[package]] [[package]]
@ -743,7 +766,7 @@ name = "mediarepo-core"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"base64", "base64",
"futures", "futures 0.3.17",
"image", "image",
"multibase", "multibase",
"multihash", "multihash",
@ -779,6 +802,7 @@ dependencies = [
"sea-orm", "sea-orm",
"serde", "serde",
"tokio", "tokio",
"tracing",
"typemap_rev", "typemap_rev",
] ]
@ -791,6 +815,8 @@ dependencies = [
"mediarepo-model", "mediarepo-model",
"serde", "serde",
"tokio", "tokio",
"tracing",
"tracing-futures",
] ]
[[package]] [[package]]
@ -1032,7 +1058,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d9facdb76fec0b73c406f125d44d86fdad818d66fef0531eec9233ca425ff4a" checksum = "8d9facdb76fec0b73c406f125d44d86fdad818d66fef0531eec9233ca425ff4a"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"cfg-if", "cfg-if 1.0.0",
"foreign-types", "foreign-types",
"libc", "libc",
"once_cell", "once_cell",
@ -1075,7 +1101,7 @@ version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"instant", "instant",
"libc", "libc",
"redox_syscall", "redox_syscall",
@ -1089,6 +1115,26 @@ version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
[[package]]
name = "pin-project"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "576bc800220cc65dac09e99e97b08b358cfab6e17078de8dc5fee223bd2d0c08"
dependencies = [
"pin-project-internal",
]
[[package]]
name = "pin-project-internal"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e8fe8163d14ce7f0cdac2e040116f22eac817edabff0be91e8aff7e9accf389"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.2.7" version = "0.2.7"
@ -1275,7 +1321,7 @@ checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e"
dependencies = [ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"crossbeam-deque", "crossbeam-deque",
"crossbeam-utils", "crossbeam-utils 0.8.5",
"lazy_static", "lazy_static",
"num_cpus", "num_cpus",
] ]
@ -1310,16 +1356,16 @@ dependencies = [
[[package]] [[package]]
name = "rmp-ipc" name = "rmp-ipc"
version = "0.7.0" version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17765aa8bd4d19dd81c53c0707192115f36ec200aea9f4557526932ac1f418e0" checksum = "f68b5ec0f51d53896979bb5364c10c6b0edf753b56570f1f2425b24ea6e85955"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"log",
"rmp-serde", "rmp-serde",
"serde", "serde",
"thiserror", "thiserror",
"tokio", "tokio",
"tracing",
"typemap_rev", "typemap_rev",
] ]
@ -1382,7 +1428,7 @@ dependencies = [
"async-stream", "async-stream",
"async-trait", "async-trait",
"chrono", "chrono",
"futures", "futures 0.3.17",
"futures-util", "futures-util",
"rust_decimal", "rust_decimal",
"sea-orm-macros", "sea-orm-macros",
@ -1517,7 +1563,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa"
dependencies = [ dependencies = [
"block-buffer", "block-buffer",
"cfg-if", "cfg-if 1.0.0",
"cpufeatures", "cpufeatures",
"digest", "digest",
"opaque-debug", "opaque-debug",
@ -1583,7 +1629,7 @@ dependencies = [
"crc", "crc",
"crossbeam-channel", "crossbeam-channel",
"crossbeam-queue", "crossbeam-queue",
"crossbeam-utils", "crossbeam-utils 0.8.5",
"either", "either",
"futures-channel", "futures-channel",
"futures-core", "futures-core",
@ -1698,7 +1744,7 @@ version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"libc", "libc",
"rand", "rand",
"redox_syscall", "redox_syscall",
@ -1779,6 +1825,16 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "tokio-executor"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb2d1b8f4548dbf5e1f7818512e9c406860678f29c300cdf0ebac72d1a3a1671"
dependencies = [
"crossbeam-utils 0.7.2",
"futures 0.1.31",
]
[[package]] [[package]]
name = "tokio-native-tls" name = "tokio-native-tls"
version = "0.3.0" version = "0.3.0"
@ -1809,6 +1865,49 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "tracing"
version = "0.1.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105"
dependencies = [
"cfg-if 1.0.0",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4"
dependencies = [
"lazy_static",
]
[[package]]
name = "tracing-futures"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2"
dependencies = [
"pin-project",
"tokio-executor",
"tracing",
]
[[package]] [[package]]
name = "typemap_rev" name = "typemap_rev"
version = "0.1.5" version = "0.1.5"
@ -1915,7 +2014,7 @@ version = "0.2.78"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"wasm-bindgen-macro", "wasm-bindgen-macro",
] ]

@ -7,6 +7,7 @@ edition = "2018"
[dependencies] [dependencies]
serde = "1.0.130" serde = "1.0.130"
tracing = "0.1.29"
[dependencies.mediarepo-core] [dependencies.mediarepo-core]
path = "../mediarepo-core" path = "../mediarepo-core"
@ -22,3 +23,6 @@ features = ["net"]
version = "0.4.19" version = "0.4.19"
features = ["serde"] features = ["serde"]
[dependencies.tracing-futures]
version = "0.2.5"
features = ["tokio-executor"]

@ -9,6 +9,7 @@ pub fn get_builder(address: &str) -> IPCBuilder {
namespaces::build_namespaces(IPCBuilder::new().address(address)).on("info", callback!(info)) namespaces::build_namespaces(IPCBuilder::new().address(address)).on("info", callback!(info))
} }
#[tracing::instrument(skip_all)]
async fn info(ctx: &Context, event: Event) -> IPCResult<()> { async fn info(ctx: &Context, event: Event) -> IPCResult<()> {
let response = InfoResponse { let response = InfoResponse {
name: env!("CARGO_PKG_NAME").to_string(), name: env!("CARGO_PKG_NAME").to_string(),

@ -29,6 +29,7 @@ impl NamespaceProvider for FilesNamespace {
impl FilesNamespace { impl FilesNamespace {
/// Returns a list of all files /// Returns a list of all files
#[tracing::instrument(skip_all)]
async fn all_files(ctx: &Context, event: Event) -> IPCResult<()> { async fn all_files(ctx: &Context, event: Event) -> IPCResult<()> {
let repo = get_repo_from_context(ctx).await; let repo = get_repo_from_context(ctx).await;
let files = repo.files().await?; let files = repo.files().await?;
@ -42,6 +43,7 @@ impl FilesNamespace {
} }
/// Searches for files by tags /// Searches for files by tags
#[tracing::instrument(skip_all)]
async fn find_files(ctx: &Context, event: Event) -> IPCResult<()> { async fn find_files(ctx: &Context, event: Event) -> IPCResult<()> {
let tags = event.data::<FindFilesByTagsRequest>()?; let tags = event.data::<FindFilesByTagsRequest>()?;
let repo = get_repo_from_context(ctx).await; let repo = get_repo_from_context(ctx).await;
@ -54,6 +56,7 @@ impl FilesNamespace {
} }
/// Adds a file to the repository /// Adds a file to the repository
#[tracing::instrument(skip_all)]
async fn add_file(ctx: &Context, event: Event) -> IPCResult<()> { async fn add_file(ctx: &Context, event: Event) -> IPCResult<()> {
let request = event.data::<AddFileRequest>()?; let request = event.data::<AddFileRequest>()?;
let path = PathBuf::from(request.path); let path = PathBuf::from(request.path);
@ -73,6 +76,7 @@ impl FilesNamespace {
} }
/// Reads the binary contents of a file /// Reads the binary contents of a file
#[tracing::instrument(skip_all)]
async fn read_file(ctx: &Context, event: Event) -> IPCResult<()> { async fn read_file(ctx: &Context, event: Event) -> IPCResult<()> {
let request = event.data::<ReadFileRequest>()?; let request = event.data::<ReadFileRequest>()?;
@ -90,6 +94,7 @@ impl FilesNamespace {
} }
/// Returns a list of available thumbnails of a file /// Returns a list of available thumbnails of a file
#[tracing::instrument(skip_all)]
async fn thumbnails(ctx: &Context, event: Event) -> IPCResult<()> { async fn thumbnails(ctx: &Context, event: Event) -> IPCResult<()> {
let request = event.data::<GetFileThumbnailsRequest>()?; let request = event.data::<GetFileThumbnailsRequest>()?;
let repo = get_repo_from_context(ctx).await; let repo = get_repo_from_context(ctx).await;
@ -108,6 +113,7 @@ impl FilesNamespace {
} }
/// Reads a thumbnail for the given thumbnail hash /// Reads a thumbnail for the given thumbnail hash
#[tracing::instrument(skip_all)]
async fn read_thumbnail(ctx: &Context, event: Event) -> IPCResult<()> { async fn read_thumbnail(ctx: &Context, event: Event) -> IPCResult<()> {
let hash = event.data::<String>()?; let hash = event.data::<String>()?;
let repo = get_repo_from_context(ctx).await; let repo = get_repo_from_context(ctx).await;

@ -20,6 +20,7 @@ impl NamespaceProvider for TagsNamespace {
impl TagsNamespace { impl TagsNamespace {
/// Returns a list of all tags in the database /// Returns a list of all tags in the database
#[tracing::instrument(skip_all)]
async fn all_tags(ctx: &Context, event: Event) -> IPCResult<()> { async fn all_tags(ctx: &Context, event: Event) -> IPCResult<()> {
let repo = get_repo_from_context(ctx).await; let repo = get_repo_from_context(ctx).await;
let tags: Vec<TagResponse> = repo let tags: Vec<TagResponse> = repo
@ -36,6 +37,7 @@ impl TagsNamespace {
} }
/// Returns all tags for a single file /// Returns all tags for a single file
#[tracing::instrument(skip_all)]
async fn tags_for_file(ctx: &Context, event: Event) -> IPCResult<()> { async fn tags_for_file(ctx: &Context, event: Event) -> IPCResult<()> {
let repo = get_repo_from_context(ctx).await; let repo = get_repo_from_context(ctx).await;
let request = event.data::<GetFileTagsRequest>()?; let request = event.data::<GetFileTagsRequest>()?;

@ -8,7 +8,7 @@ use mediarepo_core::error::RepoResult;
use mediarepo_core::settings::Settings; use mediarepo_core::settings::Settings;
use mediarepo_core::type_keys::SettingsKey; use mediarepo_core::type_keys::SettingsKey;
use mediarepo_core::utils::parse_tags_file; use mediarepo_core::utils::parse_tags_file;
use mediarepo_model::file::File; use mediarepo_model::file::File as RepoFile;
use mediarepo_model::repo::Repo; use mediarepo_model::repo::Repo;
use mediarepo_model::type_keys::RepoKey; use mediarepo_model::type_keys::RepoKey;
use mediarepo_socket::get_builder; use mediarepo_socket::get_builder;
@ -21,6 +21,8 @@ use structopt::StructOpt;
use tokio::fs; use tokio::fs;
use tokio::runtime; use tokio::runtime;
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
use tracing_flame::FlameLayer;
use tracing_subscriber::{fmt, prelude::*};
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]
#[structopt(name = "mediarepo", about = "A multimedia repository")] #[structopt(name = "mediarepo", about = "A multimedia repository")]
@ -29,6 +31,9 @@ struct Opt {
#[structopt(long, short, parse(from_os_str), default_value = ".")] #[structopt(long, short, parse(from_os_str), default_value = ".")]
repo: PathBuf, repo: PathBuf,
#[structopt(long, short)]
profile: bool,
/// The subcommand to invoke /// The subcommand to invoke
#[structopt(subcommand)] #[structopt(subcommand)]
cmd: SubCommand, cmd: SubCommand,
@ -56,8 +61,13 @@ enum SubCommand {
} }
fn main() -> RepoResult<()> { fn main() -> RepoResult<()> {
build_logger();
let opt: Opt = Opt::from_args(); let opt: Opt = Opt::from_args();
let mut _guard = None;
if opt.profile {
_guard = Some(init_tracing_flame());
} else {
build_logger();
}
match opt.cmd.clone() { match opt.cmd.clone() {
SubCommand::Init { force } => get_single_thread_runtime().block_on(init(opt, force)), SubCommand::Init { force } => get_single_thread_runtime().block_on(init(opt, force)),
@ -97,12 +107,21 @@ fn build_logger() {
.unwrap_or(LevelFilter::Info), .unwrap_or(LevelFilter::Info),
) )
.write_style(WriteStyle::Always) .write_style(WriteStyle::Always)
//.filter_module("sqlx", log::LevelFilter::Warn) .filter_module("sqlx", log::LevelFilter::Warn)
.filter_module("tokio", log::LevelFilter::Info) .filter_module("tokio", log::LevelFilter::Info)
.filter_module("tracing", log::LevelFilter::Warn)
.init(); .init();
} }
fn init_tracing_flame() -> impl Drop {
let fmt_layer = fmt::Layer::default();
let (flame_layer, _guard) = FlameLayer::with_file("./tracing.folded").unwrap();
tracing_subscriber::registry()
.with(fmt_layer)
.with(flame_layer)
.init();
_guard
}
async fn init_repo(opt: &Opt) -> RepoResult<(Settings, Repo)> { async fn init_repo(opt: &Opt) -> RepoResult<(Settings, Repo)> {
let settings = load_settings(&opt.repo.join(SETTINGS_PATH)).await?; let settings = load_settings(&opt.repo.join(SETTINGS_PATH)).await?;
let mut repo = get_repo(&opt.repo.join(&settings.database_path).to_str().unwrap()).await?; let mut repo = get_repo(&opt.repo.join(&settings.database_path).to_str().unwrap()).await?;
@ -192,7 +211,11 @@ async fn import_single_image(path: PathBuf, repo: &Repo) -> RepoResult<()> {
Ok(()) Ok(())
} }
async fn add_tags_from_tags_file(tags_path: PathBuf, repo: &Repo, file: File) -> RepoResult<()> { async fn add_tags_from_tags_file(
tags_path: PathBuf,
repo: &Repo,
file: RepoFile,
) -> RepoResult<()> {
log::info!("Adding tags"); log::info!("Adding tags");
if tags_path.exists() { if tags_path.exists() {
let tags = parse_tags_file(tags_path).await?; let tags = parse_tags_file(tags_path).await?;

Loading…
Cancel
Save