@@ -154,6 +154,23 @@ static INDEXED_KEY_UPPER_EVENT_POSITION: LazyLock<Position> = LazyLock::new(|| P
154
154
index : INDEXED_KEY_UPPER_EVENT_INDEX ,
155
155
} ) ;
156
156
157
+ /// An [`IndexedMediaContentSize`] set to it's minimal value - i.e., `0`.
158
+ ///
159
+ /// This value is useful for constructing a key range over all keys which
160
+ /// contain [`IndexedMediaContentSize`] values when used in conjunction with
161
+ /// [`INDEXED_KEY_UPPER_MEDIA_CONTENT_SIZE`].
162
+ const INDEXED_KEY_LOWER_MEDIA_CONTENT_SIZE : IndexedMediaContentSize = 0 ;
163
+
164
+ /// An [`IndexedMediaContentSize`] set to [`js_sys::Number::MAX_SAFE_INTEGER`].
165
+ /// Note that this restricts the size of [`IndexedMedia::content`], which
166
+ /// ultimately restricts the size of [`Media::content`].
167
+ ///
168
+ /// This value is useful for constructing a key range over all keys which
169
+ /// contain [`IndexedMediaContentSize`] values when used in conjunction with
170
+ /// [`INDEXED_KEY_LOWER_MEDIA_CONTENT_SIZE`].
171
+ const INDEXED_KEY_UPPER_MEDIA_CONTENT_SIZE : IndexedMediaContentSize =
172
+ js_sys:: Number :: MAX_SAFE_INTEGER as usize ;
173
+
157
174
/// The minimum possible [`Duration`].
158
175
///
159
176
/// This value is useful for constructing a key range over all keys which
@@ -1086,13 +1103,13 @@ impl<'a> IndexedPrefixKeyComponentBounds<'a, Media, IgnoreMediaRetentionPolicy>
1086
1103
fn lower_key_components_with_prefix (
1087
1104
prefix : IgnoreMediaRetentionPolicy ,
1088
1105
) -> Self :: KeyComponents < ' a > {
1089
- ( prefix, IndexedMediaContentSize :: MIN )
1106
+ ( prefix, INDEXED_KEY_LOWER_MEDIA_CONTENT_SIZE )
1090
1107
}
1091
1108
1092
1109
fn upper_key_components_with_prefix (
1093
1110
prefix : IgnoreMediaRetentionPolicy ,
1094
1111
) -> Self :: KeyComponents < ' a > {
1095
- ( prefix, IndexedMediaContentSize :: MAX )
1112
+ ( prefix, INDEXED_KEY_UPPER_MEDIA_CONTENT_SIZE )
1096
1113
}
1097
1114
}
1098
1115
@@ -1146,3 +1163,57 @@ impl<'a> IndexedPrefixKeyComponentBounds<'a, Media, IgnoreMediaRetentionPolicy>
1146
1163
( prefix, INDEXED_KEY_UPPER_DURATION_SECONDS )
1147
1164
}
1148
1165
}
1166
+
1167
+ /// The value associated with the
1168
+ /// [`retention_metadata`](IndexedMedia::retention_metadata) index of the
1169
+ /// [`MEDIA`][1] object store, which is constructed from:
1170
+ ///
1171
+ /// - The value of [`IgnoreMediaRetentionPolicy`]
1172
+ /// - The last time the associated [`IndexedMedia`] was accessed (in seconds
1173
+ /// since the Unix Epoch)
1174
+ /// - The size in bytes of the associated [`IndexedMedia::content`]
1175
+ ///
1176
+ /// [1]: crate::event_cache_store::migrations::v1::create_media_object_store
1177
+ #[ derive( Debug , Serialize , Deserialize ) ]
1178
+ pub struct IndexedMediaRetentionMetadataKey (
1179
+ #[ serde( with = "ignore_media_retention_policy" ) ] IgnoreMediaRetentionPolicy ,
1180
+ IndexedSecondsSinceUnixEpoch ,
1181
+ IndexedMediaContentSize ,
1182
+ ) ;
1183
+
1184
+ impl IndexedKey < Media > for IndexedMediaRetentionMetadataKey {
1185
+ type KeyComponents < ' a > = ( IgnoreMediaRetentionPolicy , Duration , IndexedMediaContentSize ) ;
1186
+
1187
+ fn encode (
1188
+ ( ignore_policy, last_access, content_size) : Self :: KeyComponents < ' _ > ,
1189
+ _: & IndexeddbSerializer ,
1190
+ ) -> Self {
1191
+ Self ( ignore_policy, last_access. as_secs ( ) , content_size)
1192
+ }
1193
+ }
1194
+
1195
+ impl IndexedKeyComponentBounds < Media > for IndexedMediaRetentionMetadataKey {
1196
+ fn lower_key_components ( ) -> Self :: KeyComponents < ' static > {
1197
+ Self :: lower_key_components_with_prefix ( IgnoreMediaRetentionPolicy :: No )
1198
+ }
1199
+
1200
+ fn upper_key_components ( ) -> Self :: KeyComponents < ' static > {
1201
+ Self :: lower_key_components_with_prefix ( IgnoreMediaRetentionPolicy :: Yes )
1202
+ }
1203
+ }
1204
+
1205
+ impl < ' a > IndexedPrefixKeyComponentBounds < ' a , Media , IgnoreMediaRetentionPolicy >
1206
+ for IndexedMediaRetentionMetadataKey
1207
+ {
1208
+ fn lower_key_components_with_prefix (
1209
+ prefix : IgnoreMediaRetentionPolicy ,
1210
+ ) -> Self :: KeyComponents < ' a > {
1211
+ ( prefix, INDEXED_KEY_LOWER_DURATION , INDEXED_KEY_LOWER_MEDIA_CONTENT_SIZE )
1212
+ }
1213
+
1214
+ fn upper_key_components_with_prefix (
1215
+ prefix : IgnoreMediaRetentionPolicy ,
1216
+ ) -> Self :: KeyComponents < ' a > {
1217
+ ( prefix, INDEXED_KEY_UPPER_DURATION_SECONDS , INDEXED_KEY_UPPER_MEDIA_CONTENT_SIZE )
1218
+ }
1219
+ }
0 commit comments