feat(service): Remove page caches for sticker packs
This commit is contained in:
parent
799af75bcc
commit
63d251a7f1
@ -25,7 +25,6 @@ import 'package:moxxyv2/shared/models/sticker_pack.dart';
|
|||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
|
|
||||||
class StickersService {
|
class StickersService {
|
||||||
final Map<String, StickerPack> _stickerPacks = {};
|
|
||||||
final Logger _log = Logger('StickersService');
|
final Logger _log = Logger('StickersService');
|
||||||
|
|
||||||
/// Computes the total amount of storage occupied by the stickers in the sticker
|
/// Computes the total amount of storage occupied by the stickers in the sticker
|
||||||
@ -60,8 +59,6 @@ class StickersService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<StickerPack?> getStickerPackById(String id) async {
|
Future<StickerPack?> getStickerPackById(String id) async {
|
||||||
if (_stickerPacks.containsKey(id)) return _stickerPacks[id];
|
|
||||||
|
|
||||||
final db = GetIt.I.get<DatabaseService>().database;
|
final db = GetIt.I.get<DatabaseService>().database;
|
||||||
final rawPack = await db.query(
|
final rawPack = await db.query(
|
||||||
stickerPacksTable,
|
stickerPacksTable,
|
||||||
@ -107,7 +104,7 @@ JOIN
|
|||||||
[id],
|
[id],
|
||||||
);
|
);
|
||||||
|
|
||||||
_stickerPacks[id] = StickerPack.fromDatabaseJson(
|
final stickerPack = StickerPack.fromDatabaseJson(
|
||||||
rawPack.first,
|
rawPack.first,
|
||||||
rawStickers.map((sticker) {
|
rawStickers.map((sticker) {
|
||||||
return Sticker.fromDatabaseJson(
|
return Sticker.fromDatabaseJson(
|
||||||
@ -121,23 +118,7 @@ JOIN
|
|||||||
size: await getStickerPackSizeById(id),
|
size: await getStickerPackSizeById(id),
|
||||||
);
|
);
|
||||||
|
|
||||||
return _stickerPacks[id]!;
|
return stickerPack;
|
||||||
}
|
|
||||||
|
|
||||||
Future<List<StickerPack>> getStickerPacks() async {
|
|
||||||
if (_stickerPacks.isEmpty) {
|
|
||||||
final rawPackIds = await GetIt.I.get<DatabaseService>().database.query(
|
|
||||||
stickerPacksTable,
|
|
||||||
columns: ['id'],
|
|
||||||
);
|
|
||||||
for (final rawPack in rawPackIds) {
|
|
||||||
final id = rawPack['id']! as String;
|
|
||||||
await getStickerPackById(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_log.finest('Got ${_stickerPacks.length} sticker packs');
|
|
||||||
return _stickerPacks.values.toList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> removeStickerPack(String id) async {
|
Future<void> removeStickerPack(String id) async {
|
||||||
@ -173,9 +154,6 @@ JOIN
|
|||||||
whereArgs: [id],
|
whereArgs: [id],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Remove from the cache
|
|
||||||
_stickerPacks.remove(id);
|
|
||||||
|
|
||||||
// Retract from PubSub
|
// Retract from PubSub
|
||||||
final state = await GetIt.I.get<XmppStateService>().getXmppState();
|
final state = await GetIt.I.get<XmppStateService>().getXmppState();
|
||||||
final result = await GetIt.I
|
final result = await GetIt.I
|
||||||
@ -550,9 +528,6 @@ JOIN
|
|||||||
size: size,
|
size: size,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add it to the cache
|
|
||||||
_stickerPacks[pack.hashValue] = stickerPackWithStickers;
|
|
||||||
|
|
||||||
_log.info(
|
_log.info(
|
||||||
'Sticker pack ${stickerPack.id} successfully added to the database',
|
'Sticker pack ${stickerPack.id} successfully added to the database',
|
||||||
);
|
);
|
||||||
@ -665,7 +640,6 @@ JOIN
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Cache (if includeStickers == true)
|
|
||||||
return stickerPacks;
|
return stickerPacks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user