Skip to content

Commit

Permalink
fix: merge entry data then store to db
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Jul 22, 2024
1 parent 2a91423 commit 4138b7c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
5 changes: 2 additions & 3 deletions src/renderer/src/modules/entry-column/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export function EntryColumn() {
const handleMarkReadInRange = useEntryMarkReadHandler(entriesIds)

const virtuosoOptions = {
virtuosoRef,
components: {
List: ListContent,

Expand Down Expand Up @@ -168,11 +167,11 @@ export function EntryColumn() {
<VirtuosoGrid
listClassName="grid grid-cols-2 gap-3 md:grid-cols-3 lg:grid-cols-4 px-4"
{...virtuosoOptions}
ref={virtuosoOptions.virtuosoRef}
ref={virtuosoRef}
/>
) :
(
<EntryList {...virtuosoOptions} />
<EntryList {...virtuosoOptions} virtuosoRef={virtuosoRef} />
)}
</m.div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/services/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export abstract class BaseService<T extends { id: string }> {
}

async upsertMany(data: T[]) {
this.table.bulkPut(data)
return this.table.bulkPut(data)
}

async findAll() {
Expand Down
21 changes: 14 additions & 7 deletions src/renderer/src/store/entry/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ class EntryActions {
set((state) =>
produce(state, (draft) => {
for (const item of data) {
const mergedEntry = Object.assign(
{},
draft.flatMapEntries[item.entries.id]?.entries || {},
item.entries,
)

if (!draft.entries[item.feeds.id]) {
draft.entries[item.feeds.id] = []
}
Expand All @@ -182,14 +188,15 @@ class EntryActions {
draft.flatMapEntries[item.entries.id] || {},
{
feedId: item.feeds.id,
entries: mergedEntry,
},
omit(item, "feeds"),
)

// Push feed
feeds.push(item.feeds)
// Push entry
entries.push(item.entries)
entries.push(mergedEntry)
// Push entry2Read
entry2Read[item.entries.id] = item.read || false
// Push entryFeedMap
Expand All @@ -215,12 +222,12 @@ class EntryActions {
}))

// Update database
runTransactionInScope(() => {
EntryService.upsertMany(entries)
EntryService.bulkStoreReadStatus(entry2Read)
EntryService.bulkStoreFeedId(entryFeedMap)
EntryService.bulkStoreCollection(entryCollection)
})
runTransactionInScope(() => Promise.all([
EntryService.upsertMany(entries),
EntryService.bulkStoreReadStatus(entry2Read),
EntryService.bulkStoreFeedId(entryFeedMap),
EntryService.bulkStoreCollection(entryCollection),
]))
}

hydrate(data: FlatEntryModel[]) {
Expand Down

0 comments on commit 4138b7c

Please sign in to comment.