Skip to content

Commit

Permalink
Fix all index references to col id
Browse files Browse the repository at this point in the history
Instead of just doing some of them...
  • Loading branch information
AndrewSisley committed Jan 10, 2025
1 parent 519da77 commit 72d1c46
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions internal/db/collection_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ func (c *collection) dropIndex(ctx context.Context, indexName string) error {
break
}
}
key := keys.NewCollectionIndexKey(immutable.Some(c.ID()), indexName)
key := keys.NewCollectionIndexKey(immutable.Some(c.Description().RootID), indexName)
err = txn.Systemstore().Delete(ctx, key.ToDS())
if err != nil {
return err
Expand All @@ -426,7 +426,7 @@ func (c *collection) dropIndex(ctx context.Context, indexName string) error {
func (c *collection) dropAllIndexes(ctx context.Context) error {
// callers of this function must set a context transaction
txn := mustGetContextTxn(ctx)
prefix := keys.NewCollectionIndexKey(immutable.Some(c.ID()), "")
prefix := keys.NewCollectionIndexKey(immutable.Some(c.Description().RootID), "")

keys, err := datastore.FetchKeysForPrefix(ctx, prefix.ToString(), txn.Systemstore())
if err != nil {
Expand Down Expand Up @@ -549,7 +549,7 @@ func generateIndexName(col client.Collection, fields []client.IndexedFieldDescri
if col.Name().HasValue() {
sb.WriteString(col.Name().Value())
} else {
sb.WriteString(fmt.Sprint(col.ID()))
sb.WriteString(fmt.Sprint(col.Description().RootID))
}
sb.WriteByte('_')
// we can safely assume that there is at least one field in the slice
Expand Down
4 changes: 2 additions & 2 deletions internal/db/fetcher/indexer_iterators.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func (f *IndexFetcher) newInIndexIterator(
}

func (f *IndexFetcher) newIndexDataStoreKey() keys.IndexDataStoreKey {
return keys.IndexDataStoreKey{CollectionID: f.col.ID(), IndexID: f.indexDesc.ID}
return keys.IndexDataStoreKey{CollectionID: f.col.Description().RootID, IndexID: f.indexDesc.ID}
}

func (f *IndexFetcher) newIndexDataStoreKeyWithValues(values []client.NormalValue) keys.IndexDataStoreKey {
Expand All @@ -405,7 +405,7 @@ func (f *IndexFetcher) newIndexDataStoreKeyWithValues(values []client.NormalValu
fields[i].Value = values[i]
fields[i].Descending = f.indexDesc.Fields[i].Descending
}
return keys.NewIndexDataStoreKey(f.col.ID(), f.indexDesc.ID, fields)
return keys.NewIndexDataStoreKey(f.col.Description().RootID, f.indexDesc.ID, fields)
}

func (f *IndexFetcher) createIndexIterator() (indexIterator, error) {
Expand Down
4 changes: 2 additions & 2 deletions internal/db/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (index *collectionBaseIndex) getDocumentsIndexKey(
if appendDocID {
fields = append(fields, keys.IndexedField{Value: client.NewNormalString(doc.ID().String())})
}
return keys.NewIndexDataStoreKey(index.collection.ID(), index.desc.ID, fields), nil
return keys.NewIndexDataStoreKey(index.collection.Description().RootID, index.desc.ID, fields), nil
}

func (index *collectionBaseIndex) deleteIndexKey(
Expand All @@ -213,7 +213,7 @@ func (index *collectionBaseIndex) deleteIndexKey(
// field values for all documents.
func (index *collectionBaseIndex) RemoveAll(ctx context.Context, txn datastore.Txn) error {
prefixKey := keys.IndexDataStoreKey{}
prefixKey.CollectionID = index.collection.ID()
prefixKey.CollectionID = index.collection.Description().RootID
prefixKey.IndexID = index.desc.ID

keys, err := datastore.FetchKeysForPrefix(ctx, prefixKey.ToString(), txn.Datastore())
Expand Down

0 comments on commit 72d1c46

Please sign in to comment.