@@ -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
@@ -939,6 +956,9 @@ pub struct IndexedMedia {
939
956
/// The last time the media was accessed and whether to ignore the
940
957
/// [`MediaRetentionPolicy`]
941
958
pub last_access : IndexedMediaLastAccessKey ,
959
+ /// The last the media was accessed, the size (in bytes) of the media
960
+ /// content, and whether to ignore the [`MediaRetentionPolicy`]
961
+ pub retention_metadata : IndexedMediaRetentionMetadataKey ,
942
962
/// The (possibly) encrypted metadata - i.e., [`MediaMetadata`][1]
943
963
///
944
964
/// [1]: crate::event_cache_store::types::MediaMetadata
@@ -985,6 +1005,10 @@ impl Indexed for Media {
985
1005
( self . metadata . ignore_policy , self . metadata . last_access ) ,
986
1006
serializer,
987
1007
) ,
1008
+ retention_metadata : IndexedMediaRetentionMetadataKey :: encode (
1009
+ ( self . metadata . ignore_policy , self . metadata . last_access , content. len ( ) ) ,
1010
+ serializer,
1011
+ ) ,
988
1012
metadata : serializer. maybe_encrypt_value ( & self . metadata ) ?,
989
1013
content,
990
1014
} )
@@ -1088,13 +1112,13 @@ impl<'a> IndexedPrefixKeyComponentBounds<'a, Media, IgnoreMediaRetentionPolicy>
1088
1112
fn lower_key_components_with_prefix (
1089
1113
prefix : IgnoreMediaRetentionPolicy ,
1090
1114
) -> Self :: KeyComponents < ' a > {
1091
- ( prefix, IndexedMediaContentSize :: MIN )
1115
+ ( prefix, INDEXED_KEY_LOWER_MEDIA_CONTENT_SIZE )
1092
1116
}
1093
1117
1094
1118
fn upper_key_components_with_prefix (
1095
1119
prefix : IgnoreMediaRetentionPolicy ,
1096
1120
) -> Self :: KeyComponents < ' a > {
1097
- ( prefix, IndexedMediaContentSize :: MAX )
1121
+ ( prefix, INDEXED_KEY_UPPER_MEDIA_CONTENT_SIZE )
1098
1122
}
1099
1123
}
1100
1124
@@ -1148,3 +1172,57 @@ impl<'a> IndexedPrefixKeyComponentBounds<'a, Media, IgnoreMediaRetentionPolicy>
1148
1172
( prefix, INDEXED_KEY_UPPER_DURATION_SECONDS )
1149
1173
}
1150
1174
}
1175
+
1176
+ /// The value associated with the
1177
+ /// [`retention_metadata`](IndexedMedia::retention_metadata) index of the
1178
+ /// [`MEDIA`][1] object store, which is constructed from:
1179
+ ///
1180
+ /// - The value of [`IgnoreMediaRetentionPolicy`]
1181
+ /// - The last time the associated [`IndexedMedia`] was accessed (in seconds
1182
+ /// since the Unix Epoch)
1183
+ /// - The size in bytes of the associated [`IndexedMedia::content`]
1184
+ ///
1185
+ /// [1]: crate::event_cache_store::migrations::v1::create_media_object_store
1186
+ #[ derive( Debug , Serialize , Deserialize ) ]
1187
+ pub struct IndexedMediaRetentionMetadataKey (
1188
+ #[ serde( with = "ignore_media_retention_policy" ) ] IgnoreMediaRetentionPolicy ,
1189
+ IndexedSecondsSinceUnixEpoch ,
1190
+ IndexedMediaContentSize ,
1191
+ ) ;
1192
+
1193
+ impl IndexedKey < Media > for IndexedMediaRetentionMetadataKey {
1194
+ type KeyComponents < ' a > = ( IgnoreMediaRetentionPolicy , Duration , IndexedMediaContentSize ) ;
1195
+
1196
+ fn encode (
1197
+ ( ignore_policy, last_access, content_size) : Self :: KeyComponents < ' _ > ,
1198
+ _: & IndexeddbSerializer ,
1199
+ ) -> Self {
1200
+ Self ( ignore_policy, last_access. as_secs ( ) , content_size)
1201
+ }
1202
+ }
1203
+
1204
+ impl IndexedKeyComponentBounds < Media > for IndexedMediaRetentionMetadataKey {
1205
+ fn lower_key_components ( ) -> Self :: KeyComponents < ' static > {
1206
+ Self :: lower_key_components_with_prefix ( IgnoreMediaRetentionPolicy :: No )
1207
+ }
1208
+
1209
+ fn upper_key_components ( ) -> Self :: KeyComponents < ' static > {
1210
+ Self :: lower_key_components_with_prefix ( IgnoreMediaRetentionPolicy :: Yes )
1211
+ }
1212
+ }
1213
+
1214
+ impl < ' a > IndexedPrefixKeyComponentBounds < ' a , Media , IgnoreMediaRetentionPolicy >
1215
+ for IndexedMediaRetentionMetadataKey
1216
+ {
1217
+ fn lower_key_components_with_prefix (
1218
+ prefix : IgnoreMediaRetentionPolicy ,
1219
+ ) -> Self :: KeyComponents < ' a > {
1220
+ ( prefix, INDEXED_KEY_LOWER_DURATION , INDEXED_KEY_LOWER_MEDIA_CONTENT_SIZE )
1221
+ }
1222
+
1223
+ fn upper_key_components_with_prefix (
1224
+ prefix : IgnoreMediaRetentionPolicy ,
1225
+ ) -> Self :: KeyComponents < ' a > {
1226
+ ( prefix, INDEXED_KEY_UPPER_DURATION_SECONDS , INDEXED_KEY_UPPER_MEDIA_CONTENT_SIZE )
1227
+ }
1228
+ }
0 commit comments