MCPcopy Create free account
hub / github.com/liveblocks/liveblocks / upsert

Method upsert

packages/liveblocks-react/src/ThreadDB.ts:109–131  ·  view source on GitHub ↗

Adds or updates a thread in the DB. If the newly given thread is a deleted one, it will get deleted.

(thread: ThreadDataWithDeleteInfo<TM, CM>)

Source from the content-addressed store, hash-verified

107
108 /** Adds or updates a thread in the DB. If the newly given thread is a deleted one, it will get deleted. */
109 public upsert(thread: ThreadDataWithDeleteInfo<TM, CM>): void {
110 this.signal.mutate(() => {
111 thread = sanitizeThread(thread);
112
113 const id = thread.id;
114
115 const toRemove = this.#byId.get(id);
116 if (toRemove) {
117 // Don't do anything if the existing thread is already deleted!
118 if (toRemove.deletedAt) return false;
119
120 this.#asc.remove(toRemove);
121 this.#desc.remove(toRemove);
122 }
123
124 if (!thread.deletedAt) {
125 this.#asc.add(thread);
126 this.#desc.add(thread);
127 }
128 this.#byId.set(id, thread);
129 return true;
130 });
131 }
132
133 /** Like .upsert(), except it won't update if a thread by this ID already exists. */
134 // TODO Consider renaming this to just .upsert(). I'm not sure if we really

Callers 12

upsertIfNewerMethod · 0.95
deleteMethod · 0.95
createThreadMethod · 0.45
#updateThreadMethod · 0.45
createCommentMethod · 0.45
upsertFeedsMethod · 0.45
upsertFeedMessagesMethod · 0.45
ThreadDB.test.tsFile · 0.45

Calls 6

sanitizeThreadFunction · 0.85
mutateMethod · 0.80
getMethod · 0.65
removeMethod · 0.45
addMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected