hezarfen_backend
Clone
https://git.tahinli.com/archive/hezarfen_backend.git
0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits
| 1 | //! The profile's motivational stats: the one aggregate read behind a profile |
| 2 | //! response. The counters themselves are [`crate::domain::profile`]'s; the |
| 3 | //! auto-earned badge rules next door are [`crate::domain::badge`] (pure) and |
| 4 | //! [`crate::db::badge`] (reads and writes). |
| 5 | |
| 6 | use crateDatabase; |
| 7 | use crateBadgeStats; |
| 8 | use crateProfileStats; |
| 9 | use crateUserId; |
| 10 | use crateAppError; |
| 11 | |
| 12 | /// One round trip, and only one: `courses` and `classes` arrive from the |
| 13 | /// caller, which already holds them as the `total` of the paged class and |
| 14 | /// course readers it ran for the profile's own blocks — re-counting them |
| 15 | /// here would be two extra reads for numbers already in hand. |
| 16 | /// |
| 17 | /// The pomodoro aggregate rides the per-user index, so it is a lookup and |
| 18 | /// not a scan. `finished_at IS NOT NULL` is the filter: an open stint |
| 19 | /// contributes to neither the count nor the sum — unfinished focus has no |
| 20 | /// honest duration to add. The Postgres aggregate always answers exactly |
| 21 | /// one row (`count` 0, `sum` NULL on no rows), so the empty school reads as |
| 22 | /// zeros rather than as a missing row; `COALESCE` floors the sum the same |
| 23 | /// way the old `GROUP ALL`-absent case did. |
| 24 | /// |
| 25 | /// The lifetime counters ride along as a second statement in the *same* |
| 26 | /// round rather than a [`super::badge::load`] call, which would be a second |
| 27 | /// round trip for one record lookup. It repeats that projection — the |
| 28 | /// `*_total` columns, because they are the badge rules' inputs — so the two |
| 29 | /// must move together if the shape changes. |
| 30 | pub async |
| 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 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 |