Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

database/gdb: When using the query cache, there is no cache associated object #4144

Open
jdxj opened this issue Feb 5, 2025 · 0 comments
Open
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.

Comments

@jdxj
Copy link

jdxj commented Feb 5, 2025

Go version

go version go1.23.4 darwin/amd64

GoFrame version

2.8.3

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

type Version struct { // pkg model
	// other table field

	// orm with feat
	ReleaseRules []*entity.ReleaseRule `orm:"with:version_id=id"`
	Resources    []*entity.Resource    `orm:"with:version_id=id"`
}

func (s *sVersion) LatestReleaseVersionByAppCached(ctx context.Context, in *do.Version) (*model.Version, error) {
	var ver *model.Version
	err := dao.Version.Ctx(ctx).
		// ignore some where cond
		WithAll(). // use with feat
		Cache(gdb.CacheOption{ // use cache feat
			Duration: time.Minute, // expire after one minute
			Name: fmt.Sprintf("LatestReleaseVersionByAppCached:%v:%v:%v",
				in.AppId, in.Platform, in.Version),
			Force: true,
		}).
		Scan(&ver)
	// check err
	return ver, nil
}

What did you see happen?

The associated object does not appear in the cache.

// in redis
{
    "Result": [
        {
            "app_id": 17,
            "created_at": "2025-01-16 15:04:12",
            "detail": "[{\"changelist\":\"abc\",\"language\":\"zh-CN\"}]",
            "force_update": 1,
            "id": 7,
            "platform": 2,
            "status": 1,
            "update_type": 1,
            "updated_at": "2025-02-05 11:59:40",
            "version": 74319289456263168,
            "version_raw": "v1.8.9"
        }
    ],
    "FirstResultColumn": ""
}

The log of two consecutive queries:

// 1
SHOW TABLES
SHOW FULL COLUMNS FROM `version`
SELECT `id`,`app_id`,`platform`,`version`,`version_raw`,`detail`,`status`,`force_update`,`update_type`,`created_at`,`updated_at` FROM `version` WHERE (`app_id`=17) AND (`platform`=2) AND (`version` >= 72057594037927936) AND (`status`=1) ORDER BY `version` DESC LIMIT 1
SHOW FULL COLUMNS FROM `release_rule`
SELECT `id`,`version_id`,`rule`,`rule_params` FROM `release_rule` WHERE `version_id`=7
SHOW FULL COLUMNS FROM `resource`
SELECT `id`,`version_id`,`url_crc64`,`url`,`bucket`,`object` FROM `resource` WHERE `version_id`=7

// 2
SHOW TABLES
SHOW FULL COLUMNS FROM `version`
SHOW FULL COLUMNS FROM `release_rule`
SELECT `id`,`version_id`,`rule`,`rule_params` FROM `release_rule` WHERE `version_id`=7
SHOW FULL COLUMNS FROM `resource`
SELECT `id`,`version_id`,`url_crc64`,`url`,`bucket`,`object` FROM `resource` WHERE `version_id`=7

What did you expect to see?

During the validity period, the associated object should appear in Redis, not to query the database.

@jdxj jdxj added the bug It is confirmed a bug, but don't worry, we'll handle it. label Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.
Projects
None yet
Development

No branches or pull requests

1 participant