Skip to content

Commit

Permalink
refactor: Refresh metadata in CollectionReference when updating or re…
Browse files Browse the repository at this point in the history
…freshing items

This commit updates the `CollectionReference` class to refresh the metadata when updating or refreshing items. The `updateMetadata_` method has been renamed to `refreshMetadata_` to better reflect its purpose of recalculating the collection's metadata timestamp and revision. This change aligns with the recent refactoring of other methods in the `CollectionReference` class, such as `updatePartial` to `mergeItemData`, `remove` to `removeItem`, `append` to `appendItem`, `add` to `addItem`, `getItem` to `getItemData`, and `exists` to `itemExists`. The renaming of methods improves code readability and consistency.

BREAKING CHANGE: The `updateMetadata_` method has been replaced with `refreshMetadata_` in the `CollectionReference` class. Developers should update their code to use the new method name.
  • Loading branch information
alimd committed Sep 2, 2024
1 parent e091900 commit b7108c7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/reference/src/collection-reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ export class CollectionReference<TItem extends JsonifiableObject = JsonifiableOb
this.logger__.logMethodArgs?.('updated__', {id, immediate, delayed: this.updateDelayed_});

this.hasUnprocessedChanges_ = true;
if (id !== null) this.updateMetadata_(id); // meta must updated per item
if (id !== null) this.refreshMetadata_(id); // meta must updated per item

if (immediate === false && this.updateDelayed_ === true) return;
// else
Expand All @@ -593,19 +593,19 @@ export class CollectionReference<TItem extends JsonifiableObject = JsonifiableOb
if (this.updateDelayed_ !== true) return; // another parallel update finished!
this.updateDelayed_ = false;

if (id === null) this.updateMetadata_(id); // root meta not updated for null
if (id === null) this.refreshMetadata_(id); // root meta not updated for null

if (this._freeze === true) return; // prevent save if frozen
this.updatedCallback__.call(null, this);
}

/**
* Updates the collection's metadata.
* Refresh/recalculate the collection's metadata timestamp and revision.
*
* @param itemId - The ID of the item to update.
*/
updateMetadata_(itemId: string | number | null): void {
this.logger__.logMethodArgs?.('updateMetadata_', {id: itemId});
protected refreshMetadata_(itemId: string | number | null): void {
this.logger__.logMethodArgs?.('refreshMetadata_', {id: itemId});
const now = Date.now();
this.context__.meta.rev++;
this.context__.meta.updated = now;
Expand Down

0 comments on commit b7108c7

Please sign in to comment.