Various improvements

This commit is contained in:
Ilya Laktyushin
2024-03-19 14:49:20 +04:00
parent e207ca65db
commit b261e67c34
8 changed files with 90 additions and 63 deletions

View File

@@ -10,13 +10,13 @@ public enum CachedStickerPackResult {
}
func cacheStickerPack(transaction: Transaction, info: StickerPackCollectionInfo, items: [StickerPackItem], reference: StickerPackReference? = nil) {
if let entry = CodableEntry(CachedStickerPack(info: info, items: items, hash: info.hash)) {
transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(info.id)), entry: entry)
}
if let entry = CodableEntry(CachedStickerPack(info: info, items: items, hash: info.hash)) {
transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(shortName: info.shortName.lowercased())), entry: entry)
guard let entry = CodableEntry(CachedStickerPack(info: info, items: items, hash: info.hash)) else {
return
}
transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(info.id)), entry: entry)
transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(shortName: info.shortName.lowercased())), entry: entry)
if let reference = reference {
var namespace: Int32?
var id: ItemCollectionId.Id?
@@ -57,9 +57,7 @@ func cacheStickerPack(transaction: Transaction, info: StickerPackCollectionInfo,
id = info.id.id
}
if let namespace = namespace, let id = id {
if let entry = CodableEntry(CachedStickerPack(info: info, items: items, hash: info.hash)) {
transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id))), entry: entry)
}
transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id))), entry: entry)
}
}
}

View File

@@ -270,6 +270,11 @@ func _internal_deleteStickerSet(account: Account, packReference: StickerPackRefe
}
|> mapToSignal { _ in
return account.postbox.transaction { transaction in
if let (info, _, _) = cachedStickerPack(transaction: transaction, reference: packReference) {
transaction.removeItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(info.id)))
transaction.removeItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(shortName: info.shortName.lowercased())))
}
if case let .id(id, _) = packReference {
transaction.removeItemCollection(collectionId: ItemCollectionId(namespace: Namespaces.ItemCollection.CloudStickerPacks, id: id))
}