Move conversion up in the func

This commit is contained in:
Abhishek Pandey 2023-12-03 22:46:07 -08:00
parent cddb5b2d15
commit 8ff7f77267
3 changed files with 13 additions and 17 deletions

View File

@ -10,7 +10,6 @@ import (
"time"
"github.com/alcionai/clues"
"github.com/microsoftgraph/msgraph-sdk-go/models"
"github.com/spatialcurrent/go-lazy/pkg/lazy"
"github.com/alcionai/corso/src/internal/common/idname"
@ -191,11 +190,9 @@ func newColl(
// Adds an itemID to the collection. This will make it eligible to be
// populated. The return values denotes if the item was previously
// present or is new one.
func (oc *Collection) Add(item models.DriveItemable) bool {
liteItem := custom.ToLiteDriveItemable(item)
_, found := oc.driveItems[ptr.Val(liteItem.GetId())]
oc.driveItems[ptr.Val(liteItem.GetId())] = liteItem
func (oc *Collection) Add(item custom.LiteDriveItemable) bool {
_, found := oc.driveItems[ptr.Val(item.GetId())]
oc.driveItems[ptr.Val(item.GetId())] = item
// if !found, it's a new addition
return !found
@ -220,7 +217,7 @@ func (oc *Collection) IsEmpty() bool {
// ContainsItem returns true if the collection has the given item as one of its
// children.
func (oc Collection) ContainsItem(item models.DriveItemable) bool {
func (oc Collection) ContainsItem(item custom.LiteDriveItemable) bool {
_, ok := oc.driveItems[ptr.Val(item.GetId())]
return ok
}

View File

@ -233,7 +233,7 @@ func (suite *CollectionUnitSuite) TestCollection() {
true)
for i := 0; i < test.numInstances; i++ {
coll.Add(stubItem)
coll.Add(custom.ToLiteDriveItemable(stubItem))
}
// Read items from the collection
@ -353,7 +353,7 @@ func (suite *CollectionUnitSuite) TestCollectionReadError() {
true,
false)
coll.Add(stubItem)
coll.Add(custom.ToLiteDriveItemable(stubItem))
collItem, ok := <-coll.Items(ctx, fault.New(true))
assert.True(t, ok)
@ -423,7 +423,7 @@ func (suite *CollectionUnitSuite) TestCollectionReadUnauthorizedErrorRetry() {
count.New())
require.NoError(t, err, clues.ToCore(err))
coll.Add(stubItem)
coll.Add(custom.ToLiteDriveItemable(stubItem))
collItem, ok := <-coll.Items(ctx, fault.New(true))
assert.True(t, ok)
@ -491,7 +491,7 @@ func (suite *CollectionUnitSuite) TestCollectionPermissionBackupLatestModTime()
true,
false)
coll.Add(stubItem)
coll.Add(custom.ToLiteDriveItemable(stubItem))
coll.handler = mbh
@ -1021,7 +1021,7 @@ func (suite *CollectionUnitSuite) TestItemExtensions() {
true,
false)
coll.Add(stubItem)
coll.Add(custom.ToLiteDriveItemable(stubItem))
collItem, ok := <-coll.Items(ctx, fault.New(true))
assert.True(t, ok)

View File

@ -716,7 +716,7 @@ func (c *Collections) handleDelete(
func (c *Collections) getCollectionPath(
driveID string,
item models.DriveItemable,
item custom.LiteDriveItemable,
) (path.Path, error) {
var (
pb = odConsts.DriveFolderPrefixBuilder(driveID)
@ -931,7 +931,7 @@ func (c *Collections) PopulateDriveCollections(
func (c *Collections) processItem(
ctx context.Context,
item models.DriveItemable,
di models.DriveItemable,
driveID, driveName string,
oldPrevPaths, currPrevPaths, newPrevPaths map[string]string,
seenFolders map[string]string,
@ -944,6 +944,7 @@ func (c *Collections) processItem(
skipper fault.AddSkipper,
) error {
var (
item = custom.ToLiteDriveItemable(di)
itemID = ptr.Val(item.GetId())
itemName = ptr.Val(item.GetName())
isFolder = item.GetFolder() != nil || item.GetPackageEscaped() != nil
@ -956,9 +957,7 @@ func (c *Collections) processItem(
"item_is_folder", isFolder)
if item.GetMalware() != nil {
// TODO(pandeyabs): Fix this after we move the ToLiteDriveItemable call
// to the beginning of this func.
addtl := graph.ItemInfo(custom.ToLiteDriveItemable(item))
addtl := graph.ItemInfo(item)
skip := fault.FileSkip(fault.SkipMalware, driveID, itemID, itemName, addtl)
if isFolder {