rebuilt with sdk

This commit is contained in:
or-else
2023-04-25 10:18:44 -07:00
parent 823215aea6
commit 87c74f9396
4 changed files with 23 additions and 12 deletions
+20 -9
View File
@@ -319,8 +319,8 @@ class CBuffer {
this.buffer = []; this.buffer = [];
} }
forEach(callback, startIdx, beforeIdx, context) { forEach(callback, startIdx, beforeIdx, context) {
startIdx = startIdx | 0; startIdx = Math.max(0, startIdx | 0);
beforeIdx = beforeIdx || this.buffer.length; beforeIdx = Math.min(beforeIdx || this.buffer.length, this.buffer.length);
for (let i = startIdx; i < beforeIdx; i++) { for (let i = startIdx; i < beforeIdx; i++) {
callback.call(context, this.buffer[i], i > startIdx ? this.buffer[i - 1] : undefined, i < beforeIdx - 1 ? this.buffer[i + 1] : undefined, i); callback.call(context, this.buffer[i], i > startIdx ? this.buffer[i - 1] : undefined, i < beforeIdx - 1 ? this.buffer[i + 1] : undefined, i);
} }
@@ -3909,6 +3909,9 @@ class Topic {
static isChannelTopicName(name) { static isChannelTopicName(name) {
return typeof name == 'string' && (name.substring(0, 3) == _config_js__WEBPACK_IMPORTED_MODULE_3__.TOPIC_CHAN || name.substring(0, 3) == _config_js__WEBPACK_IMPORTED_MODULE_3__.TOPIC_NEW_CHAN); return typeof name == 'string' && (name.substring(0, 3) == _config_js__WEBPACK_IMPORTED_MODULE_3__.TOPIC_CHAN || name.substring(0, 3) == _config_js__WEBPACK_IMPORTED_MODULE_3__.TOPIC_NEW_CHAN);
} }
static #isReplacementMsg(pub) {
return pub.head && pub.head.replace;
}
isSubscribed() { isSubscribed() {
return this._attached; return this._attached;
} }
@@ -4058,9 +4061,20 @@ class Topic {
return this._tinode.getMeta(this.name, params); return this._tinode.getMeta(this.name, params);
} }
getMessagesPage(limit, forward) { getMessagesPage(limit, forward) {
this._tinode._db.missingRanges(this.name, this._maxSeq, limit, forward ? this._maxSeq : undefined).then(ranges => { const gaps = [];
let query = forward ? this.startMetaQuery().withLaterData(limit) : this.startMetaQuery().withEarlierData(limit); this._messages.forEach((msg, prev) => {
const p = prev || {
seq: 0
};
if (msg.seq > p.seq + 1) {
gaps.push({
low: p.seq + 1,
hi: msg.seq
}); });
}
});
console.log("Gaps in cache found:", gaps);
let query = forward ? this.startMetaQuery().withLaterData(limit) : this.startMetaQuery().withEarlierData(limit);
return this._loadMessages(this._tinode._db, query.extract('data')).then(count => { return this._loadMessages(this._tinode._db, query.extract('data')).then(count => {
if (count == limit) { if (count == limit) {
return Promise.resolve({ return Promise.resolve({
@@ -4439,7 +4453,7 @@ class Topic {
if (startIdx != -1 && beforeIdx != -1) { if (startIdx != -1 && beforeIdx != -1) {
let msgs = []; let msgs = [];
this._messages.forEach((msg, unused1, unused2, i) => { this._messages.forEach((msg, unused1, unused2, i) => {
if (this._isReplacementMsg(msg)) { if (Topic.#isReplacementMsg(msg)) {
return; return;
} }
const latest = this.latestMsgVersion(msg.seq) || msg; const latest = this.latestMsgVersion(msg.seq) || msg;
@@ -4632,11 +4646,8 @@ class Topic {
} }
return status; return status;
} }
_isReplacementMsg(pub) {
return pub.head && pub.head.replace;
}
_maybeUpdateMessageVersionsCache(msg) { _maybeUpdateMessageVersionsCache(msg) {
if (!this._isReplacementMsg(msg)) { if (!Topic.#isReplacementMsg(msg)) {
if (this._messageVersions[msg.seq]) { if (this._messageVersions[msg.seq]) {
this._messageVersions[msg.seq].filter(version => version.from == msg.from); this._messageVersions[msg.seq].filter(version => version.from == msg.from);
if (this._messageVersions[msg.seq].isEmpty()) { if (this._messageVersions[msg.seq].isEmpty()) {
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long