@@ -19,6 +19,18 @@ struct Arguments {
19
19
debug : bool ,
20
20
}
21
21
22
+ /// Ensure that the user exists in the database.
23
+ /// If the user does not exist, insert the user into the database.
24
+ /// Users are stored in a cache to prevent querying the database for the same user multiple times.
25
+ ///
26
+ /// Arguments
27
+ /// * `owner` - The user id to check.
28
+ /// * `pool` - The database connection pool.
29
+ /// * `cache` - The cache to store user ids.
30
+ ///
31
+ /// Returns
32
+ /// * Ok(()) if the user exists or is inserted successfully.
33
+ /// * Err(sqlx::Error) if an error occurs while inserting the user.
22
34
async fn ensure_user_exists (
23
35
owner : Option < i32 > ,
24
36
pool : std:: sync:: Arc < sqlx:: Pool < sqlx:: Postgres > > ,
@@ -47,6 +59,17 @@ async fn ensure_user_exists(
47
59
Ok ( ( ) )
48
60
}
49
61
62
+ /// Process a directory entry.
63
+ /// Insert the directory into the database. If the directory already exists, update the directory.
64
+ ///
65
+ /// Arguments
66
+ /// * `entry` - The directory entry to process.
67
+ /// * `pool` - The database connection pool.
68
+ /// * `handle` - The tokio runtime handle.
69
+ /// * `cache` - The cache to store user ids.
70
+ ///
71
+ /// Returns
72
+ /// * None
50
73
fn process_directory (
51
74
entry : walkdir:: DirEntry ,
52
75
pool : std:: sync:: Arc < sqlx:: Pool < sqlx:: Postgres > > ,
@@ -74,6 +97,19 @@ fn process_directory(
74
97
} ) ;
75
98
}
76
99
100
+ /// Process a file entry.
101
+ /// Insert the file into the database. If the file already exists, update the file.
102
+ /// If the file is not inserted, retry the insert. Assume the file is not inserted due to
103
+ /// its parent directory not being inserted.
104
+ ///
105
+ /// Arguments
106
+ /// * `entry` - The file entry to process.
107
+ /// * `pool` - The database connection pool.
108
+ /// * `handle` - The tokio runtime handle.
109
+ /// * `cache` - The cache to store user ids.
110
+ ///
111
+ /// Returns
112
+ /// * None
77
113
fn process_file (
78
114
entry : walkdir:: DirEntry ,
79
115
pool : std:: sync:: Arc < sqlx:: Pool < sqlx:: Postgres > > ,
0 commit comments