hezarfen_backend
Clone
https://git.tahinli.com/Hezarfen/hezarfen_backend.git
0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits
| 1 | //! The `course_note_file` table: attachment rows for a course note, listed |
| 2 | //! newest first, with the note's file cap claimed and released in the same |
| 3 | //! write as the row. |
| 4 | //! |
| 5 | //! The `rag_doc_id` column belongs to the RAG index path alone — stamped by |
| 6 | //! [`set_rag_doc_id`] and read back by [`find_by_rag_doc_id`] — and is |
| 7 | //! deliberately absent from [`CourseNoteFile`]: no other query has to know |
| 8 | //! the column exists. |
| 9 | |
| 10 | use crateMAX_COURSE_NOTE_FILES; |
| 11 | use crate; |
| 12 | use cratePagedList; |
| 13 | use crateCourseId; |
| 14 | use crateCourseNoteId; |
| 15 | use crate |
| 16 | |
| 17 | ; |
| 18 | use crateAppError; |
| 19 | |
| 20 | /// Persist the row assembled by [`CourseNoteFile::new`], refusing once its |
| 21 | /// note already holds [`MAX_COURSE_NOTE_FILES`]. The slot and the row are |
| 22 | /// taken together by one conditional statement on the note row (the claim |
| 23 | /// CTE of `cap::claim_and_create`, spelled out at its call site — see |
| 24 | /// `crate::db::cap`) — see [`crate::db::note_file::insert`] for why that is |
| 25 | /// the only guard a concurrent insert cannot outrun. |
| 26 | pub async |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | /// Read a file's row by id alone, for the callers that have no note in |
| 64 | /// hand yet and reach the note *through* the file (the AI bridge's blob |
| 65 | /// stream). An id from any other table simply reads as `None`, which is |
| 66 | /// what keeps a personal note's file id unreachable here. |
| 67 | pub async |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | /// Read a file's row only if it belongs to `note` — callers have already |
| 84 | /// checked the note belongs to a course the caller may act on. |
| 85 | pub async |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | /// All of `note`'s attachment rows, newest first. |
| 105 | pub async |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | /// Every file row claiming `doc_id` — the content hash an indexing service |
| 121 | /// minted for a file's bytes. The column is deliberately not unique |
| 122 | /// (identical bytes produce the same doc id), so one doc may be claimed by |
| 123 | /// several files, and a file's next re-index may find its bytes already |
| 124 | /// covered. Ordered by id so callers presenting the rows do not shuffle |
| 125 | /// between reads. |
| 126 | pub async |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | /// Stamp the indexing service's `doc_id` onto a file row — what a service |
| 144 | /// staged, so the next refresh can tell whether those bytes are already |
| 145 | /// covered. A plain id-keyed update: the column is owned by the RAG index |
| 146 | /// path alone, and no cap or counter moves with it. An unknown id updates |
| 147 | /// nothing, which the caller already tolerates as best-effort. |
| 148 | pub async |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | /// The blob names (the rows' own ids, since a file's blob is named by its |
| 164 | /// id) behind every note attachment of `course` — collected *before* the |
| 165 | /// course-delete cascade wipes the rows. |
| 166 | pub async |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | /// Delete the row and give its slot back in the same transaction — the |
| 181 | /// note itself is untouched, so unlike the note-delete cascade this one |
| 182 | /// has a counter to correct. |
| 183 | pub async |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 |